473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 15205
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
38
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
4
by: Arpan | last post by:
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB" (datetime). Now when I am trying to add a new row using the...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.