Date Problem

Windows specific forum
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Date Problem

Post by Large »

Its probably something very simple again, I'm picking up Pure Basic quite well but why doesn't the code chunk below work, could someone please give me a working example, all I want to do is get day number and load dayname$ with the actual day name.

If DayOfWeek(Date) = 0
dayname$ = "Sunday"
Else
If DayOfWeek(Date) = 1
dayname$ = "Monday"
Else
If DayOfWeek(Date) = 2
dayname$ = "Tuesday"
Else
If DayOfWeek(Date) = 3
dayname$ = "Wednesday"
Else
If DayOfWeek(Date) = 4
dayname$ = "Thursday"
Else
If DayOfWeek(Date) = 5
dayname$ = "Friday"
Else
If DayOfWeek(Date) = 6
dayname$ = "Saturday"
Else
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf


Any help is much appreciated. :)

Kind regards
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Code: Select all

d.s=""
Select DayOfWeek(Date())
  Case 0: d = "Sunday"
  Case 1: d = "Monday"
  Case 2: d = "Tuesday"
  Case 3: d = "Wednesday"
  Case 4: d = "Thursday"
  Case 5: d = "Friday"
  Case 6: d = "Saturday"
EndSelect

Debug d
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Alternatively, you can get the day names for your PC's locale like this:

Code: Select all

Dim dayname$(7) ; Create 7 variables to hold day names.
For r=1 To 7
  dayname$(r)=Space(20) ; Create buffer of 20 chars to hold name.
  GetLocaleInfo_(#LOCALE_USER_DEFAULT,41+r,@dayname$(r),20) ; Get day name.
  Debug dayname$(r) ; Display it as we go.
Next
Saboteur
Enthusiast
Enthusiast
Posts: 273
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

All OK. But the problem is:
- you use Date, the compiler think it is a variable.
- you must use Date() function.
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Thanks dmoc

Post by Large »

dmoc wrote:

Code: Select all

d.s=""
Select DayOfWeek(Date())
  Case 0: d = "Sunday"
  Case 1: d = "Monday"
  Case 2: d = "Tuesday"
  Case 3: d = "Wednesday"
  Case 4: d = "Thursday"
  Case 5: d = "Friday"
  Case 6: d = "Saturday"
EndSelect

Debug d
Now that just worked perfectly, thanks again dmoc. :D
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Saboteur wrote:All OK. But the problem is:
- you use Date, the compiler think it is a variable.
- you must use Date() function.
It's no problem to use a variable with the same name as a function, as long as the variable isn't an array. :)
Post Reply