Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
date type?
#11
(03-01-2023, 09:58 AM)SMcNeill Wrote: You can get an UNIX timestamp from my posts here: https://qb64phoenix.com/forum/showthread.php?tid=65

From it, it's easy enough to turn various dates into timestamps and then subtract them to see the difference in number of days between them and such.

+1 I agree! The main work has been done by converting any date + time into a number to which minutes, hours, days, weeks added or subtracted. Years might be tricky with leap years...
b = b + ...
Reply
#12
(03-01-2023, 02:40 PM)Balderdash Wrote: SYSTEMTIME (minwinbase.h) - Win32 apps | Microsoft Learn

Simple conversion of the small sample at the bottom of that page:
(code)

Clever use of "printf()" in this one! Although I would define like 20 more examples for combinations like string, string, integer... makes me think of trig class: angle-angle-side congruent to angle-angle-side ROFL. More useful, though, would be "sprintf()" which puts the formatted text into a string.

I looked into one of the JavaScript examples on Github but it could get seriously complicated, and it boils down to the use of the "built-in" Date function. That function is probably overriden. Otherwise the function to count milliseconds is implemented, while the one that counts seconds depends on that, then the one that counts minutes relies on the one that counts seconds, and so on. Actually I didn't look into source code of many of the functions.
Reply
#13
(03-01-2023, 04:16 PM)mnrvovrfc Wrote:
(03-01-2023, 02:40 PM)Balderdash Wrote: SYSTEMTIME (minwinbase.h) - Win32 apps | Microsoft Learn

Simple conversion of the small sample at the bottom of that page:
(code)

Clever use of "printf()" in this one! Although I would define like 20 more examples for combinations like string, string, integer... makes me think of trig class: angle-angle-side congruent to angle-angle-side ROFL. More useful, though, would be "sprintf()" which puts the formatted text into a string.

I looked into one of the JavaScript examples on Github but it could get seriously complicated, and it boils down to the use of the "built-in" Date function. That function is probably overriden. Otherwise the function to count milliseconds is implemented, while the one that counts seconds depends on that, then the one that counts minutes relies on the one that counts seconds, and so on. Actually I didn't look into source code of many of the functions.
@mnrvovrfc
I've used printf a lot in QB64. It works great. sprintf also works well. Even the wide-string versions work well.
Tread on those who tread on you

Reply
#14
(03-01-2023, 09:58 AM)SMcNeill Wrote: You can get an UNIX timestamp from my posts here: https://qb64phoenix.com/forum/showthread.php?tid=65

From it, it's easy enough to turn various dates into timestamps and then subtract them to see the difference in number of days between them and such.

I love how simple that is, and can be used for so many other things. 

One question - I see it used 64-bit integers, this means it would be immune to the problem of UNIX dates not working past the year 2038?
Reply
#15
Quote:Years might be tricky with leap years...

The determination of leap years could be inserted.
Code: (Select All)
'Bestimmung von Schaltjahren - 1. Maerz 2023

Option _Explicit

Dim As Integer jahr, jahrAktuell

'Aktuell Jahreszahl ermitteln und zuweisen
jahrAktuell = Val(Right$(Date$, 4))

Locate 2, 2
Print "Zeigt ob ein Jahr ein Schaltjahr ist"
Locate 3, 2
Print "===================================="

Locate 5, 2
Input "Geben Sie das Jahr ein: ", jahr

Locate 7, 2
If (jahr Mod 4 = 0 And jahr Mod 100 <> 0) Or (jahr Mod 4 = 0 And jahr Mod 100 = 0 And jahr Mod 400 = 0) Then
  If jahr < jahrAktuell Then
    'Was, is a leap year
    Beep: Print Using "#### war ein Schaltjahr!"; jahr
  Else
    Beep: Print Using "#### ist ein Schaltjahr!"; jahr
  End If
Else
  If jahr < jahrAktuell Then
    Print Using "#### war kein Schaltjahr!"; jahr
  Else
    Print Using "#### ist kein Schaltjahr!"; jahr
  End If
End If

End
Reply
#16
(03-01-2023, 06:31 PM)Kernelpanic Wrote:
Quote:Years might be tricky with leap years...

The determination of leap years could be inserted.
Code: (Select All)
'Bestimmung von Schaltjahren - 1. Maerz 2023

Option _Explicit

Dim As Integer jahr, jahrAktuell

'Aktuell Jahreszahl ermitteln und zuweisen
jahrAktuell = Val(Right$(Date$, 4))

Locate 2, 2
Print "Zeigt ob ein Jahr ein Schaltjahr ist"
Locate 3, 2
Print "===================================="

Locate 5, 2
Input "Geben Sie das Jahr ein: ", jahr

Locate 7, 2
If (jahr Mod 4 = 0 And jahr Mod 100 <> 0) Or (jahr Mod 4 = 0 And jahr Mod 100 = 0 And jahr Mod 400 = 0) Then
  If jahr < jahrAktuell Then
    'Was, is a leap year
    Beep: Print Using "#### war ein Schaltjahr!"; jahr
  Else
    Beep: Print Using "#### ist ein Schaltjahr!"; jahr
  End If
Else
  If jahr < jahrAktuell Then
    Print Using "#### war kein Schaltjahr!"; jahr
  Else
    Print Using "#### ist kein Schaltjahr!"; jahr
  End If
End If

End

Yes, as I recall many of the date functions run on a 400 and 100 year cycle such as leap years and the Easter calculation.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#17
(03-01-2023, 06:55 PM)TerryRitchie Wrote:
(03-01-2023, 06:31 PM)Kernelpanic Wrote:
Quote:Years might be tricky with leap years...

The determination of leap years could be inserted.
Code: (Select All)
'Bestimmung von Schaltjahren - 1. Maerz 2023

Option _Explicit

Dim As Integer jahr, jahrAktuell

'Aktuell Jahreszahl ermitteln und zuweisen
jahrAktuell = Val(Right$(Date$, 4))

Locate 2, 2
Print "Zeigt ob ein Jahr ein Schaltjahr ist"
Locate 3, 2
Print "===================================="

Locate 5, 2
Input "Geben Sie das Jahr ein: ", jahr

Locate 7, 2
If (jahr Mod 4 = 0 And jahr Mod 100 <> 0) Or (jahr Mod 4 = 0 And jahr Mod 100 = 0 And jahr Mod 400 = 0) Then
  If jahr < jahrAktuell Then
    'Was, is a leap year
    Beep: Print Using "#### war ein Schaltjahr!"; jahr
  Else
    Beep: Print Using "#### ist ein Schaltjahr!"; jahr
  End If
Else
  If jahr < jahrAktuell Then
    Print Using "#### war kein Schaltjahr!"; jahr
  Else
    Print Using "#### ist kein Schaltjahr!"; jahr
  End If
End If

End

Yes, as I recall many of the date functions run on a 400 and 100 year cycle such as leap years and the Easter calculation.

I think if the tricky stuff like this can be identified then the logic can be added to handle it. 

Heck, if we simply hardcode the leap years upto the next 200 years then we're good to go right? LoL

(Although we probably need to put in the info for past years as well, but it's doable.)

Just saying...
Reply
#18
(03-01-2023, 05:29 PM)madscijr Wrote: One question - I see it used 64-bit integers, this means it would be immune to the problem of UNIX dates not working past the year 2038?

Might have to take away from this result, but I got 2924712086.77536 years!

Code: (Select All)
$CONSOLE:ONLY
dim n as _integer64, r as double
' maximum positive value of signed 64-bit
n = &H7FFFFFFFFFFFFFFF
' do milliseconds
r = n / 6000
' do minutes
r = r / 60
' do hours
r = r / 24
' do years
r = r / 365
print r

EDIT: maybe this program is not accurate, but we are future-proof for our generation and for the generation just becoming adults now. At least on 64-bit MacOS, Linux and "what"BSD there should be no such limit. I don't know the technical workings of "btrfs", "ext4", "zfs" and other such file systems but they use 64-bit addressing for "inodes" and stuff like that.

EDIT #2: It shouldn't be a problem with 64-bit representation of time then:

https://en.wikipedia.org/wiki/Unix_time#...able_times
https://en.wikipedia.org/wiki/Year_2038_problem
Reply
#19
Don't you have everything you need here?  https://qb64phoenix.com/forum/showthread...65#pid4565
Reply
#20
(03-02-2023, 02:23 AM)SMcNeill Wrote: Don't you have everything you need here?  https://qb64phoenix.com/forum/showthread...65#pid4565

Ha I was going to post that LeapYear code but I see that and the kitchen sink in there!  Big Grin
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)