0

Can any one please provide me a solution as to: a. how i create a variable in windows CMD line and store the date and time in dd-mm-yyyy hh:mm:ss format b. Also Please let me know how to find difference between two datetime's of the above format in windows command line

nikhil
  • 5
  • 4
  • When your script should run on other computers too, be sure to use a method independent of locale settings. The `%date%` variable isn't reliable at all. – Stephan Feb 28 '20 at 16:59

1 Answers1

0

There are various ways, but a python Programmer I would write a short script, so that I can fit the output to my use case.

import time import datetime print(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

Then you just need to execute the python script.

Under Windows:

c:\path\to\python3.exe script_name.py

and then it should return your desired timestamp.

The other option is, to create a date-time variable.

set datetime1=%date:~4,2%-%date:~7,2%-%date:~-4% %time:~0,2%:%time:~3,2%:%time:~6,2%

this is callable with:

echo %datetime

Output: 01-03-2020 15:00:14

nikhil
  • 5
  • 4
MunsMan
  • 118
  • 7