Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Using "dd/mm/yyyy h:mm" on Date Variables

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using "dd/mm/yyyy h:mm" on Date Variables

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change "xxx CR" and "y,yyy DB" to "+xxx" and "-yyyy" vud i Excel Worksheet Functions 6 January 31st 09 05:37 AM
Convert text "date" (DDMMMYY) to datetime value of YYYY-MM-DD - ho j.a. harriman Excel Discussion (Misc queries) 7 March 29th 07 01:20 AM
Option Explicit and Date Format "dd mmm yyyy"? Rob van Gelder[_4_] Excel Programming 11 November 10th 04 10:13 PM
TEXT(Cell1,"MMMM YYYY") to work in all locale. Jonathan Rynd Excel Programming 0 February 12th 04 06:33 PM
TEXT(Cell1,"MMMM YYYY") to work in all locale. Kevin McCartney[_2_] Excel Programming 1 February 12th 04 02:10 PM


All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"