Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

date/time format string (help with reading and writing a specific format)

Posted on 2011-09-21
5
Medium Priority
?
204 Views
Last Modified: 2012-06-21
I need to read and write Date strings using the following format:
9/19/2011 8:10:58 PM

I have code that worked for years with myStreamWriter.WriteLine(Now) and DateTime.Parse(str), but now on a new machine with different locale settings the Parse is choking, and the WriteLine is using a different format.  To maintain legacy compatibility, I need to parse and write the timestamp as shown above.  I've spend a lot of time going in circles with Parse, and ParseExact, and different Format/Cluture infos, but still can't get it just right.

Any help greatly appreciated.
0
Comment
Question by:ottenm
[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
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:OriNetworks
ID: 36573278
I think this will force it to display in US English format
.ToString(New CultureInfo("en-US"))

0
 

Author Comment

by:ottenm
ID: 36573398
No luck OriNetworks, it doesn't include the year.
0
 
LVL 17

Accepted Solution

by:
OriNetworks earned 2000 total points
ID: 36573452
See if any of these match your requirements.
http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm

Otherwise, I just format the date in my SQL query but im not sure if thats possible in your case.
SELECT Convert(varchar,getdate(),101) AS MyFormattedDate
0
 

Author Comment

by:ottenm
ID: 36573551
Thanks OriNetworks.  Using:

Now.ToString("M/d/yyyy h:mm:ss tt")
Dim dt As Date = DateTime.ParseExact(str, "M/d/yyyy h:mm:ss tt", Nothing)
0
 
LVL 40
ID: 36573570
yourDate.tostring ("MM\/dd\/yyyy hh:mm:ss tt",new Globalization.CultureInfo("EN-us"))
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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