473,396 Members | 2,129 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.

Unable to convert string to date

Hello All,

I wrote the following program.

using System;
using System.Globalization;

public class ShortDateTest
{
public static void Main(string[] args)
{
string date = @"26/04/1974";
DateTimeFormatInfo dtInfo = new DateTimeFormatInfo();
dtInfo.ShortDatePattern = @"dd/mm/yyyy";
DateTime birthDay = Convert.ToDateTime(date, dtInfo);
Console.WriteLine(birthDay.ToString());
}
}

But it throws an exception saying

Unhandled Exception: System.FormatException: Could not determine the
order of ye
ar, month, and date from dd/mm/yyyy.
at System.DateTimeParse.GetYearMonthDayOrder(String datePattern,
DateTimeForm
atInfo dtfi)
at System.DateTimeParse.GetDayOfNNY(DateTimeResult result,
DateTimeRawInfo ra
w, DateTimeFormatInfo dtfi)
at System.DateTimeParse.ProcessTerminaltState(Int32 dps,
DateTimeResult resul
t, DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyl

Why I am not able to parse this date? I have used this same methodology
successfully to parse dates of pattern dd-MMM-yy. So why doesn't it work
for dd/mm/yyyy?

thanks for your help in advance.

regards,
Abhishek.
Nov 15 '05 #1
2 10851
IIRC mm is minutes. Try a pattern of

@"dd/MM/yyyy"

HTH
Brian W

"Abhishek Srivastava" <ab*****************@nospam.net> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
Hello All,

I wrote the following program.

using System;
using System.Globalization;

public class ShortDateTest
{
public static void Main(string[] args)
{
string date = @"26/04/1974";
DateTimeFormatInfo dtInfo = new DateTimeFormatInfo();
dtInfo.ShortDatePattern = @"dd/mm/yyyy";
DateTime birthDay = Convert.ToDateTime(date, dtInfo);
Console.WriteLine(birthDay.ToString());
}
}

But it throws an exception saying

Unhandled Exception: System.FormatException: Could not determine the
order of ye
ar, month, and date from dd/mm/yyyy.
at System.DateTimeParse.GetYearMonthDayOrder(String datePattern,
DateTimeForm
atInfo dtfi)
at System.DateTimeParse.GetDayOfNNY(DateTimeResult result,
DateTimeRawInfo ra
w, DateTimeFormatInfo dtfi)
at System.DateTimeParse.ProcessTerminaltState(Int32 dps,
DateTimeResult resul
t, DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyl

Why I am not able to parse this date? I have used this same methodology
successfully to parse dates of pattern dd-MMM-yy. So why doesn't it work
for dd/mm/yyyy?

thanks for your help in advance.

regards,
Abhishek.

Nov 15 '05 #2
Yao
I think you should change the

dtInfo.ShortDatePattern = @"dd/mm/yyyy"; to

dtInfo.ShortDatePattern = @"dd/MM/yyyy";

the Month character must be capitalized.
Nov 15 '05 #3

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

Similar topics

2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
0
by: rahul gupta | last post by:
hi all i got stucked in 1 problem.i am getting err (java.text.ParseException: Unparseable date: "2007-06-29 11:34:59.0") on this line--utilDate = format.parse(convert); code is...
3
by: nklm8485 | last post by:
I'm not able to retrieve the values from a drop down in .cs file using ddl.selectedValue while I'm able to retrieve in Javascript using a hidden variable. The problem in detail: Neither This...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...

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.