473,624 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple String To Date Time

I can't imagine this is that hard but I'm sure having a struggle
finding it. How do I convert a value like "111403" do a DateTime
variable in DotNet (i.e. 11/14/2003)?

Nov 22 '05 #1
50 3975
Doug <dn******@dtgne t.com> wrote:
I can't imagine this is that hard but I'm sure having a struggle
finding it. How do I convert a value like "111403" do a DateTime
variable in DotNet (i.e. 11/14/2003)?


Use DateTime.ParseE xact, specifying a date format. eg:

DateTime dt = DateTime.ParseE xact("MMddyyyy" ,
CultureInfo.Inv ariantCulture);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
Doug <dn******@dtgne t.com> wrote:
I can't imagine this is that hard but I'm sure having a struggle
finding it. How do I convert a value like "111403" do a DateTime
variable in DotNet (i.e. 11/14/2003)?


Use DateTime.ParseE xact, specifying a date format. eg:

DateTime dt = DateTime.ParseE xact("MMddyyyy" ,
CultureInfo.Inv ariantCulture);


Whoops - forgot the all important input string!

DateTime dt = DateTime.ParseE xact (input, "MMddyyyy",
CultureInfo.Inv ariantCulture);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 22 '05 #3
Hi
I got "String.FormatE xception - String was not recognised as a valid
DateTime" when i used this DateTime.ParseE xact .
Doug, i suggest you to use ur own logic in the code to split the string
"111403" to "11/14/2003"

"Jon Skeet [C# MVP]" wrote:
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
Doug <dn******@dtgne t.com> wrote:
I can't imagine this is that hard but I'm sure having a struggle
finding it. How do I convert a value like "111403" do a DateTime
variable in DotNet (i.e. 11/14/2003)?


Use DateTime.ParseE xact, specifying a date format. eg:

DateTime dt = DateTime.ParseE xact("MMddyyyy" ,
CultureInfo.Inv ariantCulture);


Whoops - forgot the all important input string!

DateTime dt = DateTime.ParseE xact (input, "MMddyyyy",
CultureInfo.Inv ariantCulture);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 22 '05 #4
Santi,

Did you try it with
DateTime dt = DateTime.ParseE xact (input, "MMddyy",
CultureInfo.Inv ariantCulture);

In my opinion a very little obvious typo from Jon,
Cor
"Santhi Maadhaven" <Sa************ *@discussions.m icrosoft.com> schreef in
bericht news:E8******** *************** ***********@mic rosoft.com...
Hi
I got "String.FormatE xception - String was not recognised as a valid
DateTime" when i used this DateTime.ParseE xact .
Doug, i suggest you to use ur own logic in the code to split the string
"111403" to "11/14/2003"

"Jon Skeet [C# MVP]" wrote:
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
> Doug <dn******@dtgne t.com> wrote:
> > I can't imagine this is that hard but I'm sure having a struggle
> > finding it. How do I convert a value like "111403" do a DateTime
> > variable in DotNet (i.e. 11/14/2003)?
>
> Use DateTime.ParseE xact, specifying a date format. eg:
>
> DateTime dt = DateTime.ParseE xact("MMddyyyy" ,
> CultureInfo.Inv ariantCulture);


Whoops - forgot the all important input string!

DateTime dt = DateTime.ParseE xact (input, "MMddyyyy",
CultureInfo.Inv ariantCulture);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 22 '05 #5
Jon,

Why are you using so consequently the Culture.Invaria ntCulture, are you sure
that it outside the English language area does not give problems?

http://msdn.microsoft.com/library/de...reproperty.asp

Serious question

:-)

Cor

"Jon Skeet [C# MVP]" <sk***@pobox.co m> schreef in bericht
news:MP******** *************** *@msnews.micros oft.com...
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
Doug <dn******@dtgne t.com> wrote:
> I can't imagine this is that hard but I'm sure having a struggle
> finding it. How do I convert a value like "111403" do a DateTime
> variable in DotNet (i.e. 11/14/2003)?


Use DateTime.ParseE xact, specifying a date format. eg:

DateTime dt = DateTime.ParseE xact("MMddyyyy" ,
CultureInfo.Inv ariantCulture);


Whoops - forgot the all important input string!

DateTime dt = DateTime.ParseE xact (input, "MMddyyyy",
CultureInfo.Inv ariantCulture);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 22 '05 #6
Hi,
I tried it works for some strings only.If i give "11403" it fails..

"Cor Ligthert [MVP]" wrote:
Santi,

Did you try it with
DateTime dt = DateTime.ParseE xact (input, "MMddyy",
CultureInfo.Inv ariantCulture);

In my opinion a very little obvious typo from Jon,
Cor
"Santhi Maadhaven" <Sa************ *@discussions.m icrosoft.com> schreef in
bericht news:E8******** *************** ***********@mic rosoft.com...
Hi
I got "String.FormatE xception - String was not recognised as a valid
DateTime" when i used this DateTime.ParseE xact .
Doug, i suggest you to use ur own logic in the code to split the string
"111403" to "11/14/2003"

"Jon Skeet [C# MVP]" wrote:
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
> Doug <dn******@dtgne t.com> wrote:
> > I can't imagine this is that hard but I'm sure having a struggle
> > finding it. How do I convert a value like "111403" do a DateTime
> > variable in DotNet (i.e. 11/14/2003)?
>
> Use DateTime.ParseE xact, specifying a date format. eg:
>
> DateTime dt = DateTime.ParseE xact("MMddyyyy" ,
> CultureInfo.Inv ariantCulture);

Whoops - forgot the all important input string!

DateTime dt = DateTime.ParseE xact (input, "MMddyyyy",
CultureInfo.Inv ariantCulture);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Nov 22 '05 #7
Santhi,
I tried it works for some strings only.If i give "11403" it fails..

I thought that you were asking for
"111403" this one you show now, I did not see,

Can you exlain to me what
010101 than means and what
1111 than will be

Cor
Nov 22 '05 #8
010101 means 01/01/2001
1111 will be 1/1/2011

"Cor Ligthert [MVP]" wrote:
Santhi,
I tried it works for some strings only.If i give "11403" it fails..

I thought that you were asking for
"111403" this one you show now, I did not see,

Can you exlain to me what
010101 than means and what
1111 than will be

Cor

Nov 22 '05 #9
Santi,
010101 means 01/01/2001
1111 will be 1/1/2011


Why not
01/11/2001
or
11/01/2001

Cor
Nov 22 '05 #10

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

Similar topics

6
1651
by: Thomas Scheiderich | last post by:
I have the following page as test.aspx: *************************************************** <html> <head> <title>Hello and Welcome Page</title> </head> <body> <center> <% Dim CurrentDate As String
6
3779
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
2
2070
by: Deano | last post by:
Problem is that there are lots and lots of fields in an employee record. I specify a form control as the criterion for one of those fields which is the value of the primary key for that record. The idea is to copy the current record I am viewing in the form, to another table. I want to simple execute a stored query but I get a run-time error 3061, too few parameters. Expected 1. So even though I've specified the control within the...
5
2314
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
3
3738
by: Phillip Vong | last post by:
Using VS2005 w/ simple aspx in VB.net I have a simple databound textbox "LastMtgText" in a formview in the Insert template. All I want to do is make the default date of today when someone goes to Insert template so they do not have to put in todays date. Here is my code, what am I doing wrong? I know how to do this when not using Formview. '-----This puts in the current date
11
1995
by: Ground21 | last post by:
Hello. I'm new // sorry for my english :) I have to write simple program i c++. But I don't know how to code src - program should know it's name (unit1.exe so the name is "unit1" or "unit1.exe" and it's full path (with volume name - c:\programs). Which commends of c++ should I use? (please do not redirect me to 'help', because I must have some "start point" ! :)
7
1991
by: JamesG | last post by:
Hi, I need to convert the current time to the format "hh:mm:ss" and date to the format "yyyy-MM-dd". The result of both conversions needs to be of System.DateTime format. I've tried using DateTime.ParseExact and DateTimeFormatInfo but failed, most examples I see convert the final result to a string... I dont want that!
5
2832
by: GregO | last post by:
I am new to ASP and would like to know if anyone has a page that will display username, time, IP TIA - Grego
1
1297
by: cppaddict | last post by:
I have dates like "8/27" or "9/4", and I need to convert them to date objects. When choosing a year, we should go backwards until we find the first match. That is, if the script runs on Jan 1, 2008 and encounters the string "8/27", it should return a date for "8/27/2007". I've been playing around with strtodate and some other functions but I can't figure this out, and as there must be a simple solution I'd like to avoid writing a...
25
4535
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this evaluates to true when the time is not greater than dtmTime #9:32:34 PM# Why is that? and How can I get this to work? Brian
0
8249
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
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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
8633
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
8348
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
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1493
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.