enhanced formatdate/parsedate

Share your advanced PureBasic knowledge/code with the community.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

enhanced formatdate/parsedate

Post by jassing »

I had to parse some date formats for a syslog server I wrote. It's been in use for a while, but really, rather limited in use in terms of what it does/handles on a regular basis
This handles a lot more than standard formatdate() tkens %yyy%/%hh etc. as well as parsing those dates.

Maybe someone else can find use for it (or better, find bugs, improve, etc)
Windows only, due to timezone & locale parts, but if someone wants to convert that to linux/mac - have at it!

Code: Select all

;- enhDateMOD.pbi
;-
;-------------------------
;---- Enhanced Date ------
;-------------------------
; "enahanced" formatdate() 
;     Supports the standard formatdate() tokens (%hh, %ii, %mm, etc)
;     Additional tokens (case specific, use lower case)
;       %m    -   Month,  Single digit, if applicable 
;       %d    -   Day,    "
;       %h    -   Hour,   "
;       %i    -   Minute, "
;       %s    -   Second, "
;       %M    -   Month name: Jan, Feb, Mar, etc.
;       %MM   -   Month name: January, February, March, etc.
;       %D    -   Day of week: Mon, Tue, Wed, etc.
;       %DD   -   Day of week: Monday, Tuesday, Wednesday, etc.
;       %Od   -   "st", "nd" as in 1st, 2nd, for day of month (this is O oh, not 0 zero)
;       %Om   -   same but for month                          (this is O oh, not 0 zero)
;       %ampm -   am or pm
;       %AMPM -   AM or PM
;       %ms   -   milliseconds (when applicable)
;       %tzo  -   TimeZone Offset (ie: -08:00)
;       %tzn  -   TimeZone (ie: PST)
;       %tzN  -   Timezone (ie: Pacific Standard Time)
;       %RR   -   Hour, (double digit) w/o +12 for pm (double digit, ie:09, 10 instead of 22)
;       %R    -   Hour, (single digit) "
;       %wn   -   Week number *
;       #LL   -   Locale long date format  (Windows Only) (::parse() attempts to deal with this)
;       #LS   -   locale short date format (Windows Only) (::parse() can't handle this)
But I guess dateEx does all this, so it's pointless.
Last edited by jassing on Sat Jun 15, 2024 2:16 pm, edited 2 times in total.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: enhanced formatdate/parsedate

Post by jassing »

Apparently this is redundant, dateEx handles it.
Last edited by jassing on Fri Jun 14, 2024 10:36 pm, edited 1 time in total.
Little John
Addict
Addict
Posts: 4770
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: enhanced formatdate/parsedate

Post by Little John »

Windows only
For an extended cross-platform FormatDate() function – and many more date functions – see https://www.purebasic.fr/english/viewtopic.php?t=81956
Post Reply