I have the following code
set x=%date /T %
date 16/12/2012
date 15/12/2012
some stuff goes here
echo set your date
date %x% <--- getting error in that line.
pause
So how can i get the date in the format dd/mm/yy
I have the following code
set x=%date /T %
date 16/12/2012
date 15/12/2012
some stuff goes here
echo set your date
date %x% <--- getting error in that line.
pause
So how can i get the date in the format dd/mm/yy
The following code works for me:
Your assignment
set x=%date /T %
is wrong. The percent signs expand variables, they don't provide command substitution functionality.Windows already provides an automatic environment variable
%DATE%
with the current date (also a variable%TIME%
with the current time), so you can simply do this:Dale's answer helped me a lot. I modified his solution to get the time in format hhmmdd:
have you tried SET x=%date:~-10%, i know it works with windows 7.
This is tested on my system and it sets the date to required format. In case of error message of not "not enough required privileges or A required privilege is not held by the client" try running the script as Administrator. This should work fine then.
I know this is an old post, but I've found a way to do it without wmic:
At first, I've found a kind of answer and work with that:
Then I worked with this and did this one:
It deletes the spaces and the separators from the %date% command and let you use any kind of part of the date as a variable; for example if I want to set the date as YYYYMMDD The code should be like this:
If do you need the variables alone and you need to use them as you want, then you can play with the following variables:
I hope it help anyone.