On Dates and Formatting

Just starting out? Need help? Post your questions and find answers here.
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

On Dates and Formatting

Post by C87 »

Very pleased to see that v 6.0 is available. Many thanks to all involved, certainly not a trivial update.

Its announcement on the 22th prompts me to share one of my date formatting functions

Code: Select all

 Define.s Ist, mToday

Ist = Mid("stndrdthththththththththththththththththstndrdthththththththst",(((Day(Date())-1*2)*2)+1),2)
mToday = Str(Day(Date())) + Ist + " " +  Mid("JanFebMarAprMayJunJulAugSepOctNovDec", (((Month(Date())-1)* 3) + 1),3) + " " + Str(Year(Date()))

Debug mToday
There are other ways of course, but I usually prefer string handling on dates as often fewer lines of code.
If it's falling over......just remember the computer is never wrong!
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: On Dates and Formatting

Post by davido »

@C87,
Nice :) Thank you for sharing.
DE AA EB
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: On Dates and Formatting

Post by Olli »

C87 wrote: Mon Jun 27, 2022 10:20 am Very pleased to see that v 6.0 is available. Many thanks to all involved, certainly not a trivial update.

Its announcement on the 22th prompts me to share one of my date formatting functions

Code: Select all

 Define.s Ist, mToday

Ist = Mid("stndrdthththththththththththththththththstndrdthththththththst",(((Day(Date())-1*2)*2)+1),2)
mToday = Str(Day(Date())) + Ist + " " +  Mid("JanFebMarAprMayJunJulAugSepOctNovDec", (((Month(Date())-1)* 3) + 1),3) + " " + Str(Year(Date()))

Debug mToday
There are other ways of course, but I usually prefer string handling on dates as often fewer lines of code.
Too complex to be real ! :mrgreen:

Already shorter, this below, could be shorter than shorter, but... :o

Code: Select all

;by C87 (:- revision by Olli! ;)
 Define.s Ist, mToday
Define.i i = Day(Date() )
mToday = Str(i) + Mid("thestandard", $80F0000F >> i & 1 * i % 10 * 3 + 1, 2)
mToday + " " +  Mid("JanFebMarAprMayJunJulAugSepOctNovDec", (((Month(Date())-1)* 3) + 1),3) + " " + Str(Year(Date()))

Debug mToday
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: On Dates and Formatting

Post by Marc56us »

My proposal. :wink:
Not shorter, but maybe easier to understand.

Code: Select all

; By Marc56us
Select Day(Date())
    Case 1, 21, 31  : M$ = "st"
    Case 2, 22      : M$ = "nd"
    Case 3, 23      : M$ = "rd"
    Default         : M$ = "th"
EndSelect
MM$ = StringField(" Jan , Feb , Mar , Apr , May , Jun , Jul , Aug , Sep , Oct , Nov , Dec ", 
                  Month(Date()), ",")
Debug "" + Day(Date()) + M$ + MM$ + Year(Date())
PS: English is not my native language: I don't know if 4 is 4th or 4rth ? (Internet have both)
so add if needed

Code: Select all

Case 4      : M$ = "rth"
Edit: Corrected Day(Date()), not Month(Date()). Thanks ebs :wink:
Last edited by Marc56us on Tue Jun 28, 2022 2:31 pm, edited 1 time in total.
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: On Dates and Formatting

Post by C87 »

Marc56us wrote: Tue Jun 28, 2022 8:41 am
PS: English is not my native language: I don't know if 4 is 4th or 4rth ? (Internet have both)

In Britain it is always 4th......never heard of 4rth, so that must be American. Their spelling is all over the place anyway :lol:
Last edited by C87 on Thu Jun 30, 2022 9:19 am, edited 1 time in total.
If it's falling over......just remember the computer is never wrong!
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Re: On Dates and Formatting

Post by swhite »

It is 4th even in America.

Simon
Simon White
dCipher Computing
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Re: On Dates and Formatting

Post by ebs »

Marc56us wrote: Tue Jun 28, 2022 8:41 am

Code: Select all

; By Marc56us
Select Month(Date())
. . .
Don't you mean?

Code: Select all

Select Day(Date())
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: On Dates and Formatting

Post by Marc56us »

ebs wrote: Tue Jun 28, 2022 2:23 pm Don't you mean?

Code: Select all

Select Day(Date())
Yes, you're right. Corrected. Thanks :wink:
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: On Dates and Formatting

Post by mk-soft »

Depending on the language

Code: Select all

;-TOP

; Author  : mk-soft
; Version : v1.01.2
; Create  : 18.02.2021

EnableExplicit

Global Dim NameOfDays.s(6)
Global Dim NameOfMonth.s(11)
Global Dim ShortNameOfDays.s(6)
Global Dim ShortNameOfMonth.s(11)

Procedure GetLocalDateNames()
  Protected time.systemtime, i, r1, result.s{16}
  With time
    \wYear = 2021
    \wDay = 3
    \wMonth = 1
    For i = 0 To 6
      r1 = GetDateFormat_(#LOCALE_SYSTEM_DEFAULT, 0, @time, "dddd", @result, 16)
      If r1
        NameOfDays(i) = result
      EndIf
      r1 = GetDateFormat_(#LOCALE_SYSTEM_DEFAULT, 0, @time, "ddd", @result, 16)
      If r1
        ShortNameOfDays(i) = result
      EndIf
      \wDay + 1
    Next
    For i = 0 To 11
      r1 = GetDateFormat_(#LOCALE_SYSTEM_DEFAULT, 0, @time, "MMMMM", @result, 16)
      If r1
        NameOfMonth(i) = result
      EndIf
      r1 = GetDateFormat_(#LOCALE_SYSTEM_DEFAULT, 0, @time, "MMM", @result, 16)
      If r1
        ShortNameOfMonth(i) = result
      EndIf
      \wMonth + 1
    Next
  EndWith
EndProcedure : GetLocalDateNames()

CompilerIf #PB_Compiler_IsMainFile
  Define i
 
  Debug "Name Of Days"
  For i = 0 To 6
    Debug NameOfDays(i) + " / " + ShortNameOfDays(i)
  Next
  Debug "----"
 
  Debug "Name Of Month"
  For i = 0 To 11
    Debug NameOfMonth(i) + " / " + ShortNameOfMonth(i)
  Next
 
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: On Dates and Formatting

Post by Olli »

Code: Select all

Select Date() >> 16 & 31 ; day(x)
:mrgreen:
C87 wrote:In Britain[...]
Nop ! You are not in Britain. I am in Britain, in France !
And you, you just are in Great Britain ! :lol:
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: On Dates and Formatting

Post by C87 »

Nop ! You are not in Britain. I am in Britain, in France !
And you, you just are in Great Britain ! :lol:
This is just why we're so easily confused. The Romans said we were Brittania but over here we don't know who we are.
I think I'm English, or British. My friends and relations in Australia think we're Poms or Brits. If I get in the car and go to France I have to stick GB on the back. If you look on a map now there is no Great Britain any more, only the United Kingdom. If I need to select my country on a computer I can only choose UK. Foreign tourists think England is a pub. I don't know if we're a Kingdom but we certainly are not united.
If any of us are in the Olympics, or other sporting event, we become GBR. For years I thought we didn't have anyone competing.
We were all sat there saying "who is this GBR lot with our flag? Haven't they got one of their own?"

I can't understand how Britain, that isn't particularly great, can have so many different names and abbreviations. Apart from all the names we are called. At the end of the day, maybe we don't really know who we are?
But as I say I'm easily confused.

(mind you we have become extraordinarily good at riding a velo, must be the French and Italian DNA from the invasions)
If it's falling over......just remember the computer is never wrong!
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: On Dates and Formatting

Post by Olli »

The 1th ones always complain...
( I think Fred made a mistake with "th" because he was eating at the same time : in France, we only think about food ! So it was just a pronunciation problem.)
Post Reply