TheWebGuy38
asked on
Military to standart time conversion
I'm trying to do a simple conversion from military time to standard time
basically a simple
Dim time = e.OldValues("TimeOccured")
Dim timeStandard = FormatDateTime(time, DateFormat.GeneralDate))
Time being = MM/dd/yyyy hh:mm
the problem I am having is when it converts, it can't distinguish between am or pm
basically a simple
Dim time = e.OldValues("TimeOccured")
Dim timeStandard = FormatDateTime(time, DateFormat.GeneralDate))
Time being = MM/dd/yyyy hh:mm
the problem I am having is when it converts, it can't distinguish between am or pm
ASKER
yes, but for some reason it doesn't convert that way. thinks it's am even thought it's greater then 12
How do you check it is 'am' ?
ASKER
the time format would look something like
13:30 = 1:30 pm
or
04:30 = 4:40 am
so I guess one way would be to parse it and do an if then saying
if > 12 then
pm
else
am
end if
but I would think there would be a better way
13:30 = 1:30 pm
or
04:30 = 4:40 am
so I guess one way would be to parse it and do an if then saying
if > 12 then
pm
else
am
end if
but I would think there would be a better way
How do you check it is 'am' ? By that I mean after the value is converted.
ASKER
it's am if it's less then 12
Do I understand correctly
given a value eg. time = "02/28/2011 13:45"
then after the FormatDateTime you have timeStandard shows something like "02/28/2011 1:45"
given a value eg. time = "02/28/2011 13:45"
then after the FormatDateTime you have timeStandard shows something like "02/28/2011 1:45"
ASKER
close
would look like
"02/28/2011 1:45 pm"
but when it converts, it makes it an am
would look like
"02/28/2011 1:45 pm"
but when it converts, it makes it an am
so time = "02/28/2011 13:45" ==> "02/28/2011 1:45 am"
What happens when you use "#02/28/2011 13:45#", does that make any difference?
What happens when you use "#02/28/2011 13:45#", does that make any difference?
ASKER
it inserts the way it is by an obout.com datetime picker control.
that's why I need to convert it in the itemupdating
that's why I need to convert it in the itemupdating
It should be simple to add the lead and trailing # symbols to test - if it then works correctly :-)
ASKER
this is what happens on insert
Conversion from string "04/01/2011 20:07#" to type 'Date' is not valid.
Conversion from string "04/01/2011 20:07#" to type 'Date' is not valid.
#symbols both at start and end of the string
"#04/01/2011 20:07#"
"#04/01/2011 20:07#"
ASKER
Nope, didn't work :(
Hmmm.
The only thing I notice (assuming the time in the example is your current time - pm) is that GMT is currently morning - am.
Could you hard code it as "04/01/2011 08:07" and see if that appears correctly OR if it is converting it to pm.
The only thing I notice (assuming the time in the example is your current time - pm) is that GMT is currently morning - am.
Could you hard code it as "04/01/2011 08:07" and see if that appears correctly OR if it is converting it to pm.
ASKER
it looks like in the database, if it's read to a weboage 04/01/2011 08:07 would show as pm.
but when I do an update to the field, it resaves as am
but when I do an update to the field, it resaves as am
Am I correct.
It is displaying 'am' values as 'pm' and in reverse ?
It is displaying 'am' values as 'pm' and in reverse ?
ASKER
what happens is, I do an insert.
everything is fine. then I do an update and when it updates, it switches from pm to am on update.
everything is fine. then I do an update and when it updates, it switches from pm to am on update.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
when hh is more than 12 then it is pm else it is am