Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hallo everyone,
i have an error in my code that i never facing before, i would like someone who can explaint to me what going on to my code and any suggestion.

this is my code:
VB
strsql = "SELECT * FROM tams_shift WHERE shiftid = '" & shiftid & "'"
            cmd = New OdbcCommand(strsql, Conn)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                startin = Date.Parse(CSQLDate(chkdate.Date) & " " & dr("startin"))
                actualin = Date.Parse(CSQLDate(chkdate.Date) & " " & dr("actualin"))
                endin = Date.Parse(CSQLDate(chkdate.Date) & " " & dr("endin"))
                actualout = Date.Parse(CSQLDate(chkdate.Date) & " " & dr("actualout"))
        End If





when i run my code there is an error appear say "The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar."

anyone can help me here
thank you.
Posted
Comments
TnTinMn 10-Oct-13 22:55pm    
"The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar." means that the string value that you are passing an invalid datetime string to the Date.Parse() method. The only way that I could reproduce that specific error message is with an invalid time component.

ie: "2/3/2013 30:00" - hours cannot be greater then 23.

Verify what you retrieving from the datareader (dr("something")).
JOE Heart Under Blade 11-Oct-13 0:09am    
THANKS VERY MUCH TNTINMN...
ur post is really helping me out bro....
thanks again... :)
i just solve this matters after read ur comment.
thanks...

1 solution

Select Date from Database:
First check the current date format like below:
C#
lblMsg.Text = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
if (lblMsg.Text == "dd/MM/yyyy")
  txtd.Text = DateTime.Parse(dr["EventDate"].ToString()).ToString("dd/MM/yyyy");
else
  txtd.Text = DateTime.Parse(dr["EventDate"].ToString()).ToString("MM/dd/yyyy");

Add or Update: Similarly you can check either the current date format is dd/MM/yyyy OR "MM/dd/yyyy"
C#
if (lblMsg.Text == "dd/MM/yyyy")
 usinfo.BDate = DateTime.ParseExact(txtDOB.Text.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
else
usinfo.BDate = DateTime.ParseExact(txtDOB.Text.ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);

lblMsg.Text = "";
 
Share this answer
 
Comments
Maciej Los 22-Oct-15 9:05am    
Do not answer such old post. This question has been solved by OP. Please, read comments to the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900