471,089 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Datetime Format

Friends,

My hardware sends me a date format like this

15:10:20.99 UTC Mon Oct 18 2004

I need to process this format and parse to a valid SQL datetime format, how
can I do it more easily? My front-end language is C#

-Hari
Nov 16 '05 #1
2 15104
Hi Har,

If you have a DateTime object, use the SqlDateTime constructor.

If you only have a string, use the SqlDateTime.Parse method.

HTH,
Rakesh Rajan

"Harikumar G" wrote:
Friends,

My hardware sends me a date format like this

15:10:20.99 UTC Mon Oct 18 2004

I need to process this format and parse to a valid SQL datetime format, how
can I do it more easily? My front-end language is C#

-Hari

Nov 16 '05 #2
Hari,

You will need to get rid of the "UTC" bit in your input string before this
can be parsed by the SqlDateTime or DateTime classes. See the code below
which shows an example of how to get both, including converting from DateTime
back to the string format used for dates in SQL queries.

// this is the input format:
string inDateStr = "15:10:20.99 UTC Mon Oct 18 2004";

// remove the UTC bit
string parseDateStr = inDateStr.Replace("UTC", "");

// do this to create a SqlDateTime
SqlDateTime sdt = SqlDateTime.Parse(parseDateStr);
string sdtStr = sdt.ToString(); // and check the format

// do the following to create DateTime, and extract a string
// in the SQL datetime string format:
System.DateTime dt = DateTime.Parse(parseDateStr);
string dateStr = dt.ToString("yyyy-MM-dd HH:mm:ss");

HTH,
Chris.

"Rakesh Rajan" wrote:
Hi Har,

If you have a DateTime object, use the SqlDateTime constructor.

If you only have a string, use the SqlDateTime.Parse method.

HTH,
Rakesh Rajan

"Harikumar G" wrote:
Friends,

My hardware sends me a date format like this

15:10:20.99 UTC Mon Oct 18 2004

I need to process this format and parse to a valid SQL datetime format, how
can I do it more easily? My front-end language is C#

-Hari

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Fritz Switzer | last post: by
38 posts views Thread by nobody | last post: by
26 posts views Thread by Reny J Joseph Thuthikattu | last post: by
11 posts views Thread by Cor Ligthert | last post: by
4 posts views Thread by Arpan | last post: by
5 posts views Thread by js | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.