jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
war59312
Posts: 10
Joined: 07 Feb 2017 20:17
Location: U.S.A
Contact:

Re: jTimestamp.bat date/time utility - Replacement for getTimestamp.bat

#16 Post by war59312 » 10 Feb 2017 08:28

Whoops, I'm blind.

Thank you. :)

Edit: Well, still off by 1 second often:

Code: Select all

REM Get Script Start Time Using jTimestamp.cmd
CALL jTimestamp -f {ums} -r t1

REM Fancy Time Stamp
for /F "tokens=*" %%a in (
   'jTimestamp -d %t1% /F " {WKD} {MTH} {D}, {yyyy} {H12}:{NN}:{SS}{PM}"'
) do (
   
   set Timestamp=%%a   
)

set "Timestamp=%Timestamp::00am=am%"
set "Timestamp=%Timestamp::00pm=pm%"
echo %Timestamp%

REM Get Script End Time Using jTimestamp.cmd
CALL jTimestamp -f {ums} -r t2

REM Fancy Time Stamp
for /F "tokens=*" %%a in (
   'jTimestamp -d %t2% /F " {WKD} {MTH} {D}, {yyyy} {H12}:{NN}:{SS}{PM}"'
) do (
   
   set Timestamp=%%a   
)

set "Timestamp=%Timestamp::00am=am%"
set "Timestamp=%Timestamp::00pm=pm%"
echo %Timestamp%

CALL jTimestamp -d %t2%-%t1% -f " {ud} Days {h} Hours {n} Minutes And {s} Seconds" -u
ECHO.
BTW without the "-u" it shows 19 hours. Bug?

Edit 2: BTW using "-c "OUS=-1"" does not work either since its not always off.

dbenham
Expert
Posts: 2254
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#17 Post by dbenham » 16 Jan 2018 22:26

I got a private message from user asun reporting a nasty bug with ISO 8601 week date computation
asun wrote: Hi Dave,

I was looking for a DOS batch function that will give me the date of a given week number and day and your JTimestamp.bat is just what I need! Thank you for writing and posting this code.
However, it's my luck that I immediately stumbled upon what appears to be a bug but I don't have the knowledge to fix it. It outputs a totally wrong date for 2018 Week 8 Day 3 (Wed) and 2018 Week 9 Day 3 (Wed) which correspond to the last two weeks of February:

% JTimestamp -D "ISO 2018-W07-3"
2018-02-14T00:00:00.000-05:00

% JTimestamp -D "ISO 2018-W08-3"
2017-12-27T00:00:00.000-05:00

% JTimestamp -D "ISO 2018-W09-3"
2017-12-27T00:00:00.000-05:00

% JTimestamp -D "ISO 2018-W10-3"
2018-03-07T00:00:00.000-05:00

As you can see, Week 7 and Week 10 worked fine but Weeks 8 and 9 returned a 2017 date. I guess the 28-day February somehow screwed this up. Could you kindly look into this to see if you could fix this bug? Much appreciated.
Thanks for reporting the bug asun.

It turns out the computation always failed if the week is 08 or 09 because I forgot to specify the base when I parsed the integer value. So the parseInt() function was seeing the leading 0 as an octal indicator, and the invalid octal values of 8 and 9 were somehow interpreted as 0. I checked, and all other parseInt() usage properly specified base 10.

So here is v2.1 that fixes the bug:
jTimestamp2.1.zip
(10.21 KiB) Downloaded 98 times

Dave Benham

asun
Posts: 1
Joined: 16 Jan 2018 19:05

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#18 Post by asun » 17 Jan 2018 09:41

Thanks for the lightning-fast response Dave. Very much appreciated. I could be staring at the code for weeks and still wouldn't figure out this base 10 thing.
I have downloaded and tested v2.1 and everything works fine. Thanks again for creating and sharing this very useful program. - Andy

MG_0720
Posts: 1
Joined: 08 Jul 2019 06:17

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#19 Post by MG_0720 » 08 Jul 2019 06:20

Is there any way to get the actual week number of the year to be output or set in variable for further reference?
as a TV broadcast company we need that week number out the 52 weeks?

penpen
Expert
Posts: 1685
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#20 Post by penpen » 08 Jul 2019 11:14

You could use a "for/f"-loop to store that value into an environment variable:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
for /f %%a in ('jTimestamp /F "{ISOWK}"') do set "isoWk=%%~a"
set isoWk
goto :eof
Sidenote: You should be aware, that some years have 53 weeks (more specific: every year starting on thursday).


penpen

dbenham
Expert
Posts: 2254
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#21 Post by dbenham » 11 Jul 2019 11:02

MG_0720 wrote:
08 Jul 2019 06:20
Is there any way to get the actual week number of the year to be output or set in variable for further reference?
as a TV broadcast company we need that week number out the 52 weeks?
Everything is fully documented in the built in help: JTIMESTAMP /?
or JTIMESTAMP /?? for paged help

If you want the result in a variable then simply use the -R option:

Code: Select all

   -R ReturnVariable

      Save the timestamp in ReturnVariable instead of displaying it.
      ReturnVariable is unchanged if an error occurs.
      Default is empty, meaning write to stdout.


The week number may be easily gotten, depending on which week numbering system you use. jTimestamp uses the ISO 8601 standard, where week 1 includes the first Thursday of the calendar year, and weeks start with Monday = 1.

The following week formats are available for use with the -F (format) option:

Code: Select all

{ISOWY}  yyyy
         ISO 8601 week numbering year
         Dec 29, 30, or 31 may belong to the next Jan year
         Jan 01, 02, or 03 may belong to the prior Dec year

{ISOWK}  ww
         ISO 8601 week number
         Week 01 is the week with the year's first Thursday

{ISOWD}  d
         ISO 8601 day of week: 1=Monday, 7=Sunday

{ISODTW} yyyyWwwd
         Compressed ISO 8601 week date format

{ISO-DTW} yyyy-Www-d
         ISO 8601 week date format


Dave Benham

Post Reply