?
Solved

Controlling date format when writing to a file

Posted on 2003-03-29
6
Medium Priority
?
147 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:jonleehacker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
DeAn earned 400 total points
ID: 8232275
try:

Format(TimeOfArrival, "h:mm:ss AMPM")
0
 

Expert Comment

by:narang
ID: 8232319
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
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8232350
Format(TimeOfArrival, "h:mm:ss AMPM") returns: 3:57:00 PM

leave out an "h" in the format
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jonleehacker
ID: 8232617
Thank you,

Works like a charm!!!!
0
 
LVL 1

Author Comment

by:jonleehacker
ID: 8255775
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.
0
 
LVL 1

Author Comment

by:jonleehacker
ID: 8256046
I figured it out. Here's the correct method:

Write #2, ;

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

Write #2,
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question