theDay is the day of the month, a simple numerical value, 11 (for 11 Jan
2007). Format(theDay, "ddd") accepts this number 11, and tells you "Wed".
But 11 is not today's date, the date corresponding to 11 is Wednesday,
January 11, 1900. The bug is in the way you used the functions one after the
other. If you instead use this line:
wkday2 = Format(theDate, "ddd")
you get the expected result of "Thu". But you should keep dates in date
variables, not in strings, because you never know how VBA might misinterpret
the text. Here's how you should rewrite your code, including declaring your
variables as the types you expect them to be, not what VBA arbitrarily
assigns:
Sub DateStuff()
Dim theDate As Date
Dim theDateString As String
Dim theMonth As Integer
Dim theDay As Integer
Dim wkday As String
theDate = Now
theDateString = Format(theDate, "mm-dd-yy")
theMonth = Month(theDate)
theDay = Day(theDate)
wkday = Format(theDate, "ddd")
End Sub
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______
wrote in message
ps.com...
sub stuff()
theDate = Format(Now,"mm-dd-yy")
themonth = Month(theDate)
theDay = Day(theDate)
wkday = Format(theDay, "ddd")
end sub
.... for some reason when i use the Format() function, it takes the day
before. Is there an option statement that I am missing or something?
The first format string returns the correct day, but the second one
returns the previous day. Am i missing an option statement?