"Tom Del Rosso" <(E-Mail Removed)> wrote in message
news:W3aje.230581$(E-Mail Removed)...
> "Pegasus (MVP)" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> >
> > Whenever possible I use %date%. AFAIK it is not possible
> > to extract dd/mm/yy by just using %date% - I ***must***
> > first write it to the screen with an "echo" command. If you
> > know of a way then please post it!
>
> I'm surprised because I thought it was just as easy. Maybe we have a
> miscommunication, but this is what I meant. These are fragments from two
of
> my batch files.
>
> -----------
> set backupdate=%date: =_%
> set backupdate=%backupdate:/=-%
> -----------
>
> The next one re-orders the year, month, etc, so the variable can go into
> names that are sortable. The output of ('time/t') is 12 hour and doesn't
> have fractional seconds, but I wanted 24 hour format so (%time%) was
> preferable here. The fractional seconds are discarded. I took a
"snapshot"
> of the date and time simultaneously because it might run around midnight.
> (I inserted blank lines after the lines that are split by the newsreader
to
> make it readable.)
>
> -----------
> :Settimestamp
> REM set environment variable with 'd-a-t-e_t-i-m-e'
> set timesnapshot=%date% %time%
> for /f "Tokens=1-4 Delims=/ " %%A in ("%timesnapshot%") do set
> dt=%%D-%%B-%%C_%%A
>
> for /f "Tokens=3,4 Delims=: " %%A in ("%timesnapshot%") do set tm=%%A-%%B
> REM it is desirable to have 1-digit hours with leading 0 so sorting comes
> out right
>
> REM if second character is "-" then the hour has 1 digit
> if "%tm:~1,1%"=="-" set tm=0%tm%
> set dttm=%dt%_%tm%
> goto :eof
> -----------
>
> --
>
> Reply in group, but if emailing add
> 2 more zeros and remove the obvious.
Very nice code, and an elegant alternative to my own suggestion.
|