LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Date conversion doesn't make sense

Change
CDate(".5")
to
CDate(Val(".5"))

or even don't use CDate at all, only use Val()

Reason is CDate assumes user the string is already 'like' a time, rather
than an ordinary number

Regards,
Peter T


wrote in message
...
I am having problems with converting text to date using the cdate
function
When I convert .5 into a format of HH:MM AM/PM it becomes 12:00 PM
which makes sense because noon is half of a day

When I convert 0.5 into a format of HH:MM AM/PM it becomes 12:05 AM
which doesn't make sense

When I convert 0.50 into a format of HH:MM AM/PM it becomes 12:50 AM
which also doesn't make sense

When I convert 0.500 into a format of HH:MM AM/PM it becomes 12:00 PM

Below is a msgbox that demonstrates this.
What is happening?

Sub test1()
MsgBox "The string "".5"" converts to " & Format(CDate(".5"), "MMM
dd yyyy HH:MM AM/PM") _
& vbLf & "The string ""0.5"" converts to " & Format(CDate("0.5"),
"MMM dd yyyy HH:MM AM/PM") _
& vbLf & "The string ""0.50"" converts to " &
Format(CDate("0.50"), "MMM dd yyyy HH:MM AM/PM") _
& vbLf & "The string ""0.500"" converts to " &
Format(CDate("0.500"), "MMM dd yyyy HH:MM AM/PM")
End Sub

Thanks for any help
Merlyn



 
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
make signed over-punch conversion work in a macro Alex Excel Programming 0 January 4th 07 05:27 AM
Converting a date from nonsense to sense RobertM Excel Discussion (Misc queries) 1 April 24th 06 02:21 PM
Does this make sense? Tom Excel Programming 0 August 24th 04 06:24 PM


All times are GMT +1. The time now is 07:15 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"