Skip navigation

JSI Tip 3481. A universal date parser.


In various scripts on these pages, including tip 0531 » How do I parse a date into month, day, and year and tip 0721 » General purpose date math routine, I parsed the date /t command into its' component month, day, and year.

If your date format is not mm/dd/yy, you had to modify these scripts to get them to work in your environment.

If a script could determine the date format for the environment it runs it, the script could be universal, working in any date format.

If you open a CMD prompt and type date and then press Enter, you can see that the second line of the output does contain a model of the date format. Borrowing a technique from tip 1986 » How can I get an accurate time in a batch job, we can use the echo.|date syntax to press the enter key for us.

NOTE: See the changes required for Windows XP, Windows Server 2003, and later operating systems.



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish