date type? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: date type? (/showthread.php?tid=1514) |
date type? - madscijr - 02-28-2023 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? RE: date type? - mnrvovrfc - 02-28-2023 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://staging.qb64phoenix.com/showthread.php?tid=1459 RE: date type? - madscijr - 02-28-2023 (02-28-2023, 09:21 AM)mnrvovrfc Wrote: No, unfortunately. 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 RE: date type? - mnrvovrfc - 02-28-2023 (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. RE: date type? - TerryRitchie - 02-28-2023 (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. RE: date type? - madscijr - 03-01-2023 (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? 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! RE: date type? - mnrvovrfc - 03-01-2023 (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. RE: date type? - SMcNeill - 03-01-2023 You can get an UNIX timestamp from my posts here: https://staging.qb64phoenix.com/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. RE: date type? - SpriggsySpriggs - 03-01-2023 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 RE: date type? - madscijr - 03-01-2023 (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. Good to know about! However, I was thinking of something a little more cross-platform... |