PDA

View Full Version : Getting Weekday as String and working with dates



chamster
09-23-2007, 11:55 PM
When i work with my code below

Dim d as Date
MsgBox Weekday(d)


i get a number. Is there a pre-programmed way to
a) get a string as a name,
b) make monday the first day of the week as God intended,
c) make that number 0 (this is only a minor issue)?

Also, is there a smooth way to e.g. list all the days of a month (variably many, depending on what month/year it is)? I can surely code an algorithm but it would be neat to have a smooth way (few lines of code).

mdmackillop
09-24-2007, 12:06 AM
Look at the WeekDay Function in VBA help to set the start day. Look at User-Defined Date/Time Formats to return a string.

Bob Phillips
09-24-2007, 12:33 AM
When i work with my code below

Dim d as Date
MsgBox Weekday(d)


i get a number. Is there a pre-programmed way to
a) get a string as a name,



[QUOTE=chamster]MsgBox Format(d,"dddd")



b) make monday the first day of the week as God intended,

Done. Monday is the first day of the week.

c) make that number 0 (this is only a minor issue)?


Also, is there a smooth way to e.g. list all the days of a month (variably many, depending on what month/year it is)? I can surely code an algorithm but it would be neat to have a smooth way (few lines of code).



Dim i As Long
Dim d As Date

For i = 1 To 31
d = DateSerial(Year(Date), Month(Date), i)
Debug.Print d
If Month(d) <> Month(d + 1) Then Exit For
Next i

chamster
09-24-2007, 02:30 AM
Done. Monday is the first day of the week.


Not on my system, it isn't. For some reason, Sunday is the first day, which is very annoying. Where does that come from?

Bob Phillips
09-24-2007, 03:12 AM
I was being flippant, as I didn't understand what you meant. I think I do now, so try

Weekday(date,2)

Bob Phillips
09-24-2007, 03:14 AM
BTW, it comes from the second argument to Weekday, firstdayofweek, which has values of

vbUseSystem 0 Use the NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

RichardSchollar
09-24-2007, 04:24 AM
I was being flippant

Bob: you, flippant?! Surely not!!

:devil2:

Bob Phillips
09-24-2007, 04:29 AM
Bob: you, flippant?! Surely not!!

:devil2:

Watch it, otherwise I'll be up the M3 to claim those bottles of Sapphire.

Anyway, sometimes answering posts does affect one a tad!

RichardSchollar
09-24-2007, 05:07 AM
I think after 6400+ helpful posts on the forum, you're allowed a dose of flippancy :)

And I've switched to Plymouth for the timebeing (the drink, not the location!) - so I'm afraid you'd be out of luck with the Sapphire!

Richard

Bob Phillips
09-24-2007, 05:14 AM
I go to Plymouth often, and I like Plymouth gin too. Moved, or just working away?

RichardSchollar
09-24-2007, 11:22 AM
Still in the fair town of Eastleigh :) Altho have decided that I make a better Excel developer than I do an accountant, so presently casting around for alternative work. Throwing aside that safety net of a monthly pay cheque is proving harder than expected though!

We'll have to meet up for that gin sometime.

Richard

Bob Phillips
09-24-2007, 12:15 PM
Still in the fair town of Eastleigh :) Altho have decided that I make a better Excel developer than I do an accountant, so presently casting around for alternative work. Throwing aside that safety net of a monthly pay cheque is proving harder than expected though!

Christ, you must be a crummy accountant <vbg>

Seriously though, it is hard. It took me 5 years of the job getting more and more oppressive before I could cast off the golden handcuffs.


We'll have to meet up for that gin sometime.

I'm in abstinence at the monet, but I look forward to it.

RichardSchollar
09-25-2007, 12:33 AM
Christ, you must be a crummy accountant <vbg>

Cheeky b*stard! First round is definitely gonna be on you in that case!


Seriously though, it is hard. It took me 5 years of the job getting more and more oppressive before I could cast off the golden handcuffs.

Yeah - that's exactly what I'm finding...