Link to home
Start Free TrialLog in
Avatar of jonleehacker
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
ASKER CERTIFIED SOLUTION
Avatar of DeAn
DeAn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of narang
narang

Salut!

   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
Format(TimeOfArrival, "h:mm:ss AMPM") returns: 3:57:00 PM

leave out an "h" in the format
Avatar of jonleehacker

ASKER

Thank you,

Works like a charm!!!!
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.
I figured it out. Here's the correct method:

Write #2, ;

Print #2, "#" & CntClient.TimeOfArrival & "#,";

Write #2,