Author Topic: Ticks to Date  (Read 689 times)

stanl

  • Pundit
  • *****
  • Posts: 1800
Ticks to Date
« on: October 21, 2021, 12:57:56 pm »
I had done this before using an SQLite formula, but can't find the original formula I used. Basically I am getting data returned as ticks which are nanoseconds since Jan 1, 1601 [a Gregorian Calendar thing, maybe]. Anyway, the simple script below doesn't fail, just doesn't return correct date. I tried to work around with HugeMath Extender but that got me more tick'd off :( .  Anyway, await the slings and arrows for this bad code: [CLR TimeSpan would work but not ready for WB Primetime, and in PS a simple Get-Date 635241312000000000 w
works.
Code: Winbatch

ticks = 635241312000000000 ;should be January 1, 2014 12:00:00 AM
ticks = (ticks/10000000)
Message("",ticks)
TickBase="1601:01:01:00:00:00"
AddTime = "0000:00:00:00:00:%ticks%"
Later=TimeAdd(TickBase, AddTime)
Message(TickBase, Later)
 

td

  • Tech Support
  • *****
  • Posts: 4354
    • WinBatch
Re: Ticks to Date
« Reply #1 on: October 21, 2021, 02:03:55 pm »
Code: Winbatch
; Ticts are the granularity of the Windows OS system time
; and a tick is 100 nanoseconds.
ticks =  ObjectType('i8',635241312000000000)
Date1 = ObjectClrNew("System.DateTime",ticks)
strDate = Date1.ToString()
exit
 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 4354
    • WinBatch
Re: Ticks to Date
« Reply #2 on: October 21, 2021, 02:58:36 pm »
As it turns out your question did lead to the discovery of an issue with ObjectClrNew's handling of 64-bit integers. That is why the example I posted had to use the ObjectType function. (The example works just fine because of the call to ObjectType.)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

  • Pundit
  • *****
  • Posts: 1800
Re: Ticks to Date
« Reply #3 on: October 22, 2021, 03:02:48 am »
Thanks. Nice to circle back to the CLR; 1601 was not a good year.  Between that base date, the Excel base date [1900 or 1899] and the Unix base of 1970 - I'm reminded of the Chicago song 'does anyone really know what time it is?' ???

jmburton2001

  • Full Member
  • ***
  • Posts: 134
Re: Ticks to Date
« Reply #4 on: October 22, 2021, 08:36:12 am »
1601 was not a good year.

I'm not so sure about that. The premiere of Shakespeare's Hamlet occurred that year.  ;)

stanl

  • Pundit
  • *****
  • Posts: 1800
Re: Ticks to Date
« Reply #5 on: October 22, 2021, 11:52:12 am »
I'm not so sure about that. The premiere of Shakespeare's Hamlet occurred that year.  ;)


Sure. Look how that ended. 8)


[EDIT]: Darn! I thought someone would come back with "does anybody really care" - [Chicago reference]

td

  • Tech Support
  • *****
  • Posts: 4354
    • WinBatch
Re: Ticks to Date
« Reply #6 on: October 22, 2021, 01:12:43 pm »
For the non-bardolators among us:

“There is nothing either good or bad, but thinking makes it so.”
- William Shakespeare, Hamlet
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade