Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Oops!
Day 11 in Excel is Wednesday, January 11, 1900. Day 11 in VBA is Wednesday, January 10, 1900. The difference is that VBA knows 1900 was not a leap year. Microsoft knew it was a leap year when they created Excel, but for compatibility with Lotus 1-2-3, which didn't know from leap years (nor from business models apparently), they pretended it was a leap year. But I got the Wednesday part right. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "Jon Peltier" wrote in message ... 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? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
permanent conversion of 1904 date format to 1900 date format | Excel Worksheet Functions | |||
How do I convert dd/mm/yy date format to yyddd Julian date format | Excel Worksheet Functions | |||
Convert date + time text format to date format | Excel Worksheet Functions | |||
code to convert date from TEXT format (03-02) to DATE format (200203) | Excel Programming | |||
Change a date in text format xx.xx.20xx to a recognised date format | Excel Programming |