Get weekday?

BlitzPlus Forums/BlitzPlus Programming/Get weekday?

BachFire(Posted 2004) [#1]
Hey,

Is it possible to get the weekday? You know, like 'CurrentDate$()', but just the name of the day?


Rob Farley(Posted 2004) [#2]
It's not a standard blitz function.


Cold Harbour(Posted 2004) [#3]
In B+ you need to use something like Zellers Congruence to work it out. I think there's an example in the code arcs or I can post my version if you like.


Kevin_(Posted 2004) [#4]
Try this....

[Code]
; Get the day of the week example by Prof.
;
Graphics 640,480,32,2
SetBuffer BackBuffer()

Day$=GetDayOfTheWeek(15,04,2004) ; <- Put any date in here

Text 10,10,Day$
Flip
WaitKey()
End


Function GetDayOfTheWeek$(day,month,year)
; Returns the day of the week.
; day, month & year are integers i.e. 15 04 2004
a=(14-month)/12
y=year-a
m=month+(12*a)-2
d=(day+y+(y/4)-(y/100)+(y/400)+((31*m)/12))Mod 7 ;Ooouch!
Select d
Case 0:Weekday$="Sunday"
Case 1:Weekday$="Monday"
Case 2:Weekday$="Tuesday"
Case 3:Weekday$="Wednesday"
Case 4:Weekday$="Thursday"
Case 5:Weekday$="Friday"
Case 6:Weekday$="Saturday"
Default:Weekday=""
End Select
Return Weekday$
End Function

[/Code]


Kevin_(Posted 2004) [#5]
Don't thank me then will you?


Eikon(Posted 2004) [#6]
Ouch indeed.


soja(Posted 2004) [#7]
This is what I would do. Easy peasy, as they say.
;.lib "Kernel32.dll"
;GetDate%(iLocale%, iFlags%, iDate%, iFormat$, oDate$, iSizeBuf%):"GetDateFormatA"

date$ = String(" ", 15)
GetDate(0, 0, 0, "dddd", date, Len(date))
Notify date



Kevin_(Posted 2004) [#8]
Easy peasy, as they say.


But it is also very limited.

It only retrieves the day for todays date. My function allows the user to retrieve the day of the week for any date given. This is useful for calendars/Pims etc.


soja(Posted 2004) [#9]
But it is also very limited.

Not so limited as you might think... You can pass in any of these strings to get different info.

d Day of month as digits with no leading zero for single-digit days.
dd Day of month as digits with leading zero for single-digit days.
ddd Day of week as a three-letter abbreviation.
dddd Day of week as its full name.
M Month as digits with no leading zero for single-digit months.
MM Month as digits with leading zero for single-digit months.
MMM Month as a three-letter abbreviation.
MMMM Month as its full name.
y Year as last two digits, but with no leading zero for years less than 10.
yy Year as last two digits, but with leading zero for years less than 10.
yyyy Year represented by full four digits.
gg Period/era string.



For example,
day$ = String(" ", 150)
GetDate(0, 0, 0, "d dd ddd dddd M MM MMM MMMM y yy yyyy gg", day, Len(day))
Notify day

...returns:
17 17 Sat Saturday 4 04 Apr April 4 04 2004

...at least right now. =) And you can pick and choose.

Also, you can still use the WinAPI call if you want to enter in any date you like:
;.lib "Kernel32.dll"
;GetDateAny%(locale%, dwFlags%, lpDate*, lpFormat$, lpDateStr$, size%):"GetDateFormatA"

day$ = String(" ", 15)
time = CreateBank(16)
PokeShort(time, 0, 2004) ; Year
PokeShort(time, 2, 4) ; Month
PokeShort(time, 6, 17) ; Day
GetDateAny(0, 0, time, "dddd", day, Len(day))
Notify day

Just options depending on how complicated you want to get and how much you trust WinAPI over your own code (or vice versa). =)


Sonari Eclipsi Onimari(Posted 2007) [#10]
Heck, I'll thank you! THIS IS EXACTLY WHAT I NEEDED! THANK YOU!!!!!!


Seldon(Posted 2008) [#11]
This doesn't work anymore. The program crashes when GetDateFormat() is called.

UPDATED: I find out the problem (known in Blitz): if you pass a NULL pointer, you can't simply pass a '0' , you also need to change the function definition in the .decls file.

For example:
;.lib "Kernel32.dll"
GetDateFormat%(Locale%,dwFlags%,lpDate*,lpFormat$,lpDateStr$,cchDate%):"GetDateFormatA"
GetDateFormat_NULL%(Locale%,dwFlags%,lpDate%,lpFormat$,lpDateStr$,cchDate%):"GetDateFormatA"

See lpDate* and lpDate% .


Andres(Posted 2010) [#12]
A warning to anyone who uses this function for getting week day - It returns the week day in the language that the windows is installed with.