Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am calculating dates in a loop and using the following date format:
DateFormat = "dd/mm/yyyy h:mm" When I print to the Immediate Window, the first hour (hour ending 0) shows up without the h:mm extension. I expected to see: 01/01/2005 00:00:00. Why is this? Thanks CurrentDate = Format(DateSerial(CurrentYear, CurrentMonth, CurrentDay), DateFormat) Debug.Print CurrentDate CurrentDate = Format(CurrentDate + 1 / 24, DateFormat) Debug.Print CurrentDate Immediate Window: 01/01/2005 01/01/2005 01:00:00 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Obviously CurrentDate is Dimmed as Date. Since it has no time value the
first time, it doesn't display. I added a ", cdbl(CurrentDate)" to each Debug.Print line to illustrate 1/1/05 38353 1/1/05 1:00:00 AM 38353.0416666667 Using format as an intermediate in the assignment statement does't affect what is stored in the Date Serial. In fact, you would get the same result without it: Sub F() Dim currentDate As Date DateFormat = "dd/mm/yyyy h:mm" CurrentYear = 2005 CurrentMonth = 1 CurrentDay = 1 currentDate = DateSerial(CurrentYear, _ CurrentMonth, CurrentDay) Debug.Print currentDate, CDbl(currentDate) currentDate = currentDate + 1 / 24 Debug.Print currentDate, CDbl(currentDate) End Sub Again produces: 1/1/05 38353 1/1/05 1:00:00 AM 38353.0416666667 -- Regards, Tom Ogilvy "ExcelMonkey" wrote in message ... I am calculating dates in a loop and using the following date format: DateFormat = "dd/mm/yyyy h:mm" When I print to the Immediate Window, the first hour (hour ending 0) shows up without the h:mm extension. I expected to see: 01/01/2005 00:00:00. Why is this? Thanks CurrentDate = Format(DateSerial(CurrentYear, CurrentMonth, CurrentDay), DateFormat) Debug.Print CurrentDate CurrentDate = Format(CurrentDate + 1 / 24, DateFormat) Debug.Print CurrentDate Immediate Window: 01/01/2005 01/01/2005 01:00:00 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to change "xxx CR" and "y,yyy DB" to "+xxx" and "-yyyy" | Excel Worksheet Functions | |||
Convert text "date" (DDMMMYY) to datetime value of YYYY-MM-DD - ho | Excel Discussion (Misc queries) | |||
Option Explicit and Date Format "dd mmm yyyy"? | Excel Programming | |||
TEXT(Cell1,"MMMM YYYY") to work in all locale. | Excel Programming | |||
TEXT(Cell1,"MMMM YYYY") to work in all locale. | Excel Programming |