Jump to content
Matthew D

Formatting and Comparisons of Dates in Script

Recommended Posts

Hi all, 

I'm trying to make some evaluations in an Automate script based on comparing dates - I'll be pulling a date from Powershell for storage in an EDF on one day, then checking it in subsequent runs. In particular I need to check, is the date in the EDF the same as 'today' which I think I have to compare against %when%. 

%when% is timestamp - I'd normally format it down to just leave the date. I can't figure out how to get started to achieve this?

How do you normally handle this?

Thanks

Matthew

Share this post


Link to post
Share on other sites

Date handling is always going to be a complex task. Are you dealing with a multi time zone installation? Are you intending to compare times across zones?

If you are facing anything complex then it may be better to generate numeric values based against some fixed date in the past, like seconds-since-1/1/2000 and using UTC as a base, you could then store that as an int in an EDF. You can then use a powershell function or a mysql function to convert back to a date and to then calculate differences.

If you want to just keep it simple, then remember that EDFs are text, so you will want to force the format of all dates and times to a fixed format (yyyy-mm-dd hh:mm:ss highly recommended) when outputting from Powershell and mysql queries and then converting back to internal dates when reading them back into mysql/powershell. This way you will avoid the date-back-to-front issue when dealing with using the default date formatting. 

This method doesn't handle multiple time zones, but you could by converting all times to GMT/UTC.

Share this post


Link to post
Share on other sites

That's helpful, thanks. I'm going to assume it's safer to do all my date evaluations in calls out to Powershell - bit of a round-trip, but at least its predictable. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...