Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
date type?
#1
Do we have a native date/time type, with all the associated functions (dateadd, datediff, date to UNIX epoch & vice-versa, timezone operations, etc.) or has anyone built an equivalent library in QB64PE or related?
Reply
#2
No, unfortunately.

Might have to make them up from C/C++ libraries:

https://linux.die.net/man/3/mktime

Or let's wait what Balderdash has to say about it LOL.

If you need to print dates in human-readable format there is this:

https://qb64phoenix.com/forum/showthread.php?tid=1459
Reply
#3
(02-28-2023, 09:21 AM)mnrvovrfc Wrote: No, unfortunately.

Might have to make them up from C/C++ libraries:

https://linux.die.net/man/3/mktime

Or let's wait what Balderdash has to say about it LOL.

If you need to print dates in human-readable format there is this:

https://qb64phoenix.com/forum/showthread.php?tid=1459

Thanks, I do have code to print human readable dates, which is useful, it would just be very useful to have all the date calculations and time zone formatting functions we find in other languages. 

After seeing the good folks here do things like string math, I am convinced that all things are possible in BASIC, so hopefully someone smarter than me will be willing to take this on! LoL

(I would think that a lot of this stuff has been tackled before in the old QuickBasic / QBasic days, or in other languages which can be ported over or serve as a model?)

Anyway, Happy Tuesday to you!

PS how DO you pronounce mnrvovrfc anyway? 
I just think of myxlplic from the old Superfriends cartoons, LoL!

https://youtube.com/watch?v=6EKiHzdWX8g

https://youtube.com/watch?v=9g7C-hC5ups

:-D
Reply
#4
(02-28-2023, 01:04 PM)madscijr Wrote: PS how DO you pronounce mnrvovrfc anyway? 

Just call me "Minerva" or "Brooke" or whatever other sensible nickname bplus gives me. Big Grin
Reply
#5
(02-28-2023, 08:14 AM)madscijr Wrote: Do we have a native date/time type, with all the associated functions (dateadd, datediff, date to UNIX epoch & vice-versa, timezone operations, etc.) or has anyone built an equivalent library in QB64PE or related?

Back in the early 90's I had to write many of these date functions for a drug testing program I wrote for my local municipality. If I remember correctly most were fairly easy to calculate, except for Easter, which uses a convoluted equation.

With a little Internet research these should be fairly easy to find written in other source code and converted to QB64. I'll add it to my list of libraries to create but won't be able to get to it for some time as I'm working on others right now.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#6
(02-28-2023, 07:50 PM)TerryRitchie Wrote:
(02-28-2023, 08:14 AM)madscijr Wrote: Do we have a native date/time type, with all the associated functions (dateadd, datediff, date to UNIX epoch & vice-versa, timezone operations, etc.) or has anyone built an equivalent library in QB64PE or related?

Back in the early 90's I had to write many of these date functions for a drug testing program I wrote for my local municipality. If I remember correctly most were fairly easy to calculate, except for Easter, which uses a convoluted equation.

With a little Internet research these should be fairly easy to find written in other source code and converted to QB64. I'll add it to my list of libraries to create but won't be able to get to it for some time as I'm working on others right now.

That would be great - I'm not working on anything where I need date calculations right now, 
I just think this kind of thing would be very useful (especially for business apps). 

A number of years back I worked on a big JavaScript library where we needed all kinds of date conversion, formatting, validation, and calculations, and we ended up with close to 50 functions, and there was still tons more to do. The basic functions aren't too hard to roll on your own, it's just that when you consider things like time zones and leap years and business days and so on, the list quickly grows! Then date libraries like moment.js started appearing and it became apparent that we could stop being in the date/time business, lol. 

Mainly the ones I use in apps like Excel, Outlook VBA, etc., are DATEDIFF, DATEADD, CDATE, comparisons, and formatting. 

But you can see here just how deep you can go! 

On the Microsoft side:
and Javascript:
That's all I have for now!
Reply
#7
(03-01-2023, 01:56 AM)madscijr Wrote: A number of years back I worked on a big JavaScript library where we needed all kinds of date conversion, formatting, validation, and calculations, and we ended up with close to 50 functions, and there was still tons more to do. The basic functions aren't too hard to roll on your own, it's just that when you consider things like time zones and leap years and business days and so on, the list quickly grows!

I had thought JavaScript already had those kind of functions built in. I almost wrote something about it but then thought about one of the developers of QB64PE.
Reply
#8
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.
Reply
#9
One could do it with Win32 API but I don't have the code handy right now. This is a good reference if you know what you're doing. If not, I can assist.

SYSTEMTIME (minwinbase.h) - Win32 apps | Microsoft Learn

Simple conversion of the small sample at the bottom of that page:

Code: (Select All)
Option Explicit
$NoPrefix
$Console:Only

Type SYSTEMTIME
    As Unsigned Integer wYear, wMonth, wDayOfWeek
    As Unsigned Integer wDay, wHour, wMinute
    As Unsigned Integer wSecond, wMilliseconds
End Type

Declare CustomType Library
    Sub printf (format As String, Byval arg1 As Unsigned Integer, Byval arg2 As Unsigned Integer)
    Sub GetSystemTime (ByVal lpSystemTime As Offset)
    Sub GetLocalTime (ByVal lpSystemTime As Offset)
End Declare

Dim As SYSTEMTIME st, lt

GetSystemTime (Offset(st))
GetLocalTime (Offset(lt))

printf "The system time is: %02d:%02d" + Chr$(10) + Chr$(0), st.wHour, st.wMinute
printf " The local time is: %02d:%02d" + Chr$(10) + Chr$(0), lt.wHour, lt.wMinute
Tread on those who tread on you

Reply
#10
(03-01-2023, 02:40 PM)Balderdash Wrote: One could do it with Win32 API but I don't have the code handy right now. This is a good reference if you know what you're doing. If not, I can assist.

SYSTEMTIME (minwinbase.h) - Win32 apps | Microsoft Learn

Simple conversion of the small sample at the bottom of that page:

Code: (Select All)
Option Explicit
$NoPrefix
$Console:Only

Type SYSTEMTIME
    As Unsigned Integer wYear, wMonth, wDayOfWeek
    As Unsigned Integer wDay, wHour, wMinute
    As Unsigned Integer wSecond, wMilliseconds
End Type

Declare CustomType Library
    Sub printf (format As String, Byval arg1 As Unsigned Integer, Byval arg2 As Unsigned Integer)
    Sub GetSystemTime (ByVal lpSystemTime As Offset)
    Sub GetLocalTime (ByVal lpSystemTime As Offset)
End Declare

Dim As SYSTEMTIME st, lt

GetSystemTime (Offset(st))
GetLocalTime (Offset(lt))

printf "The system time is: %02d:%02d" + Chr$(10) + Chr$(0), st.wHour, st.wMinute
printf " The local time is: %02d:%02d" + Chr$(10) + Chr$(0), lt.wHour, lt.wMinute

Good to know about! 
However, I was thinking of something a little more cross-platform...
Reply




Users browsing this thread: 4 Guest(s)