1.

Solve : Problems using the TIME function?

Answer»

When I use the following set statement before noon, I get a blank in the time (HOURS) portion of the statement.
Any ideas.

set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%


The result is:

20061116 849That is going to depend on the way your regional settings are configured for your time format.  For your particular case, you can probably do this:
Code: [Select]set CurrentHour=%TIME:~0,2%
if %CurrentHour% LSS 10 set CurrentHour0%CurrentHour%
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%CurrentHour%%TIME:~3,2%if you have Python on windows

Code: [Select]import time
print time.strftime("%Y%m%d%H%m%S", time.localtime())

output:
Code: [Select]'20061017071053'
Thanks guys, I have added to code to the script. I will check it tomorrow morning (when the time is right).

Ken
OK, slight problem with the code supplied by GuruGary.
1) There was a syntax error (missing =)
2) It left a space in between the 0 and 8 (200610170 849)
No problem, the code you gave me was enough for me to solve the problem.

Thanks again. So far so Good

Here is the revised version

REM Set up the current date and time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR=0%TIME:~1,1%
set CURDATETIME=%DATE:~8,2%%DATE:~3,2%%DATE:~0,2%%CURRENTHOUR%%TIME:~3,2%


As for the Python solution, thanks but I do not want to INSTALL anything on my client machines unless absolutely required. I want to keep the install as NATIVE as possible. I am also reproducing this on a UNIX machine (I have a working version, just have to make it now WORK similar to this now for support reasons).

Thanks again for all your help guys. This site is now part of my development Favourites.
Ken Quote

As for the Python solution, thanks but I do not want to install anything on my client machines unless absolutely required. I want to keep the install as NATIVE as possible. I am also reproducing this on a UNIX machine (I have a working version, just have to make it now work similar to this now for support reasons).
Ken

FYI, you do not need to reproduce if you use scripts made in Python/Perl. Those scripts can be ported to unix with little or no modification at all. Well anyway, its your CHOICE.



Discussion

No Comment Found