jonleehacker
asked on
Controlling date format when writing to a file
Hi,
I have a date variable called
TimeOfArrival that contains #3:57:00 PM#
If I do debug.print I get: 3:57:00 PM
which is good.
But when I write it to a text file I get: #1899-12-30 15:57:00# which is not good.
What I want to get when I write to file is: #3:57:00 PM#
Any help apprecitated greatly,
Jon
I have a date variable called
TimeOfArrival that contains #3:57:00 PM#
If I do debug.print I get: 3:57:00 PM
which is good.
But when I write it to a text file I get: #1899-12-30 15:57:00# which is not good.
What I want to get when I write to file is: #3:57:00 PM#
Any help apprecitated greatly,
Jon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Format(TimeOfArrival, "h:mm:ss AMPM") returns: 3:57:00 PM
leave out an "h" in the format
leave out an "h" in the format
ASKER
Thank you,
Works like a charm!!!!
Works like a charm!!!!
ASKER
Actually I just checked again and those solutions don't work. They format it correctly but because the format function returns a string and I am writing to file I get:
"3:57:00 PM"
rather than #3:57:00 PM# which is what I need to maintain the datatype in the file.
"3:57:00 PM"
rather than #3:57:00 PM# which is what I need to maintain the datatype in the file.
ASKER
I figured it out. Here's the correct method:
Write #2, ;
Print #2, "#" & CntClient.TimeOfArrival & "#,";
Write #2,
Write #2, ;
Print #2, "#" & CntClient.TimeOfArrival & "#,";
Write #2,
To solve your problem you just have to format your hour before writing it into the file :
In VB6
Format(TimeOfArrival , "HH:MM:SS AM/PM")
In VB.NET
Format(TimeOfArrival , "HH:MM:SS tt")
I hope that it will help,
Have a nice day or evening ;+)
Narang