0

I am currently using the below code to return a date format from a XP embedded machine, it is a fairly basic version of XP, the below code returns the correct format on a windows 7 machine (10-02-2015) but on the XP machine it returns (Tue), how can I modify the code to return the correct format, without changing the XP time format on the machine

Set timestamp=%DATE:/=-%
user396581
  • 109
  • 1
  • 2
  • 9

1 Answers1

1

The date format includes the day-of-week at the beginning in many environments - use:

set DT=%DATE:/=-%
set timestamp=%DT:~4%

to set timestamp the way is on your Win7 environment; however, this approach is not exactly portable, just be aware.

EDIT

This will reorder the date and time to something that sorts properly ... and it does happen to also be the order used in Europe:

set DT=%DATE:/=-%
set timestamp=%DT:~10,4%-%DT:~4,5%

keeping in mind, this still isn't portable across systems.

EDIT

Whoop, you wanted UK, which isn't the same as other places - that would be:

set timestamp=%DT:~7,3%%DT:~4,3%%DT:~10,4%
John Castleman
  • 1,543
  • 10
  • 11
  • Thanks for the quick reply, this now puts the date in, which is exactly what I want, just one quick question, it puts the date in USA format MM-DD-YYYY can it be converted to UK format DD-MM-YYYY, if possible – user396581 Feb 10 '15 at 15:06