473,811 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert string to datetime

I have string 20070502144551 and I would like to convert this to datetime:

2007-05-02 14:45:51

Is there some function?

Regards,Simon
Jul 13 '07 #1
4 8623
On Fri, 13 Jul 2007 07:03:16 -0700, simonZ
<si*********@st udio-moderna.comwrot e:
I have string 20070502144551 and I would like to convert this to
datetime:

2007-05-02 14:45:51
DateTime.ParseE xact("200705021 44551", "yyyyMMddhhmmss ", null);

Or, something like that anyway.
Jul 13 '07 #2
If I try this, I get an error:
String was not recognized as a valid DateTime.

Any idea?

Thanks,Simon

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Fri, 13 Jul 2007 07:03:16 -0700, simonZ
<si*********@st udio-moderna.comwrot e:
>I have string 20070502144551 and I would like to convert this to
datetime:

2007-05-02 14:45:51

DateTime.ParseE xact("200705021 44551", "yyyyMMddhhmmss ", null);

Or, something like that anyway.

Jul 13 '07 #3
On Jul 13, 10:49 am, "simonZ" <simon.zu...@st udio-moderna.comwrot e:
If I try this, I get an error:
String was not recognized as a valid DateTime.

Any idea?

Thanks,Simon

"Peter Duniho" <NpOeStPe...@nn owslpianmk.comw rote in message

news:op******** *******@petes-computer.local. ..
On Fri, 13 Jul 2007 07:03:16 -0700, simonZ
<simon.zu...@st udio-moderna.comwrot e:
I have string 20070502144551 and I would like to convert this to
datetime:
2007-05-02 14:45:51
DateTime.ParseE xact("200705021 44551", "yyyyMMddhhmmss ", null);
Or, something like that anyway.- Hide quoted text -

- Show quoted text -
This worked for me

DateTime.ParseE xact("200705020 24551", "yyyyMMddhhmmss ", null);

I changed the 14 to 02, you may need a format provider to convert to
24 hour time.

Jul 13 '07 #4
simonZ wrote:
If I try this, I get an error:
String was not recognized as a valid DateTime.

Any idea?

Thanks,Simon

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
>On Fri, 13 Jul 2007 07:03:16 -0700, simonZ
<si*********@s tudio-moderna.comwrot e:
>>I have string 20070502144551 and I would like to convert this to
datetime:

2007-05-02 14:45:51
DateTime.Parse Exact("20070502 144551", "yyyyMMddhhmmss ", null);

Or, something like that anyway.
Use HH instead of hh, and use CultureInfo.Inv ariantCulture instead of null.

--
Göran Andersson
_____
http://www.guffa.com
Jul 13 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
16338
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
5
18727
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
19
8771
by: simon | last post by:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM" Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error message: String was not recognized as a valid DateTime. What should I do? Use replace function and mid function on string and at the end convert it to date? Thank you for your answer, Simon
2
4798
by: ziggislaw | last post by:
hello how can I convert DateTime from "25.12.2005" to "2005-12-25 00:00:00.000" ? Now I have DateTime as string (I get it from <asp:label>). Thanks
14
7976
by: Me | last post by:
Hi all I am getting a really bizzare error on when I convert a string into a datetime: The code is : DateTime dt1 = Convert.ToDateTime("10 Sep 2005"); Console.WriteLine(dt1.Year);
4
35901
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
5
3796
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
3
1749
by: Oren | last post by:
Hi, I use DateTime.Now and Serialize an object into XML field (Sql 2005). the problem is that: select CONVERT(datetime, '2006-10-09T13:54:06.9248089+02:00') ERROR: Conversion failed when converting datetime from character string. Any idea ?
7
16729
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T GetValue<T(string objName) { T results;
9
10858
by: mcfly1204 | last post by:
I have read through various posts on converting a string into the datetime format, but cannot resolve my situation. I have a string in the format of 'yyyymmddthhmmss.sssz' that I would like to convert to datetime. My previous attempts: DateTime dt = DateTime.Parse(string); DateTime dt = Convert.ToDateTime(string); DateTime dt = XmlConvert.ToDateTime(string, format); where format = 'yyyymmddthhmmss.sssz' I should note that the string...
0
9727
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.