Page 1 of 1

Date Problem

Posted: Fri May 09, 2003 10:38 am
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

Posted: Fri May 09, 2003 11:00 am
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

Posted: Fri May 09, 2003 11:38 am
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

Posted: Fri May 09, 2003 11:44 am
by Saboteur
All OK. But the problem is:
- you use Date, the compiler think it is a variable.
- you must use Date() function.

Thanks dmoc

Posted: Fri May 09, 2003 12:15 pm
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

Posted: Fri May 09, 2003 12:20 pm
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. :)