Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date problem Excel 97

Status
Not open for further replies.

Hawkide

Technical User
Oct 8, 2003
159
US
Excel 97

Two textboxes on a form

User enters a date into txb1 (format = mm/dd/yy)
User enters a time into txb2 (format = hhmm)

Then I use:

dteStart = CDate(txb1 & " " & Left(txb2, 2) & ":" & Right(txb2, 2))


where dteStart is of type Date

I use dteStart in the header of a worksheet. It will display something along the lines of:

02/05/2004 11:59:00 PM

The problem occurrs when the user enters 0000 for txb2 (this is midnight). In that case the header shows:

02/05/2004

Why does it not display the 00:00?


 
CDate will attempt to turn a string into a valid date. Dates are inernally stored as an Double, with the integer part representing the number of days since Dec 30th 1899 and the fractional part representing fractions of a day since midnight. CDate for midnight will therefore show an Integer. You just need to format the strings in the textboxes appropriately:

dtestart = tb1 & " " & Left(tb2, (Len(tb2) - 2)) & ":" & Right(tb2, 2)

You will still need to check for valid input into the textboxes. You might look at the IsDate function, or the DateTimePicker control

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thanks...I guess I'll keep it as a string and only use the CDate when I make chronological comparisons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top