andycharger Posted February 2, 2004 Posted February 2, 2004 I am having a problem with dates (still) I have a date 0f 1st April 2003 In the UK (where I am) it would read as "01/04/2003" I am parsing my string before sending it in a SQL statment like this strDate = DateTime.Parse(Request.Form("txtDateRec")) The problem is that this is converting it in the database to "04/01/2003" (american format) What do I need to do in my parse command to ensure it goes in my DB as "01/04/2003"???? Help please!!! Quote
Administrators PlausiblyDamp Posted February 2, 2004 Administrators Posted February 2, 2004 try Dim ci As System.Globalization.CultureInfo = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB") Dim d As DateTime = DateTime.Parse("01/04/2003", ci) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
andycharger Posted February 2, 2004 Author Posted February 2, 2004 Hi PLausibly, I tried that but it still doe not change the formatting. I stepped into the code and looked at the variables. They still appear as #11/1/2003# when im trying to put in 1st November 2003 (01/11/2003) Any more ideas mate? Quote
Administrators PlausiblyDamp Posted February 2, 2004 Administrators Posted February 2, 2004 Whoops - only read half your question Dim ci As System.Globalization.CultureInfo = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB") Dim d As DateTime = DateTime.Parse("01/04/2003", ci) Dim s As String s = d.ToLongDateString() 'May work s = d.ToString(ci.DateTimeFormat) 'Should work Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Gurus* Derek Stone Posted February 2, 2004 *Gurus* Posted February 2, 2004 The DateTime.ParseExact() method may offer a clearer solution. http://www.xtremedotnettalk.com/showthread.php?s=&threadid=81354 Quote Posting Guidelines
andycharger Posted February 2, 2004 Author Posted February 2, 2004 PLausibly, This still is not working. I watched the locals and left the code exactly as you entered it. In the locals, it converts the date to the following: #4/1/2004# Whereas it should say "01/04/2004" Is the ci bit doing anything? What imports do I need in the project to ensure these are all there? Quote
Administrators PlausiblyDamp Posted February 2, 2004 Administrators Posted February 2, 2004 s = d.ToString("dd/MM/yyyy") although the bit s = d.ToString(ci.DateTimeFormat) formatted okay for me - did include the time portion though. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
andycharger Posted February 3, 2004 Author Posted February 3, 2004 Neither of those are formatting my date at all. No matter what I change the specificculture to. I therefore think the culture is not being picked up. In fact, I have done both of these to force it d = DateTime.Parse("01/08/2004",ci) strDateRec = d.ToString("dd/mm/yyyy") d = DateTime.Parse("01/08/2004",ci) strDateRec = d.ToString(ci.DateTimeFormat) the first one puts outputs the following in the watch window "01/00/2004" obviously that fails on the insert. can you confirm what imports I need to put at the top of my page or in my project? Quote
Administrators PlausiblyDamp Posted February 3, 2004 Administrators Posted February 3, 2004 What database are you using and what tool are you using to display the date from the database? Have you considered a format of strDateRec = d.ToString("dd/mmm/yyyy") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
andycharger Posted February 3, 2004 Author Posted February 3, 2004 thanks all (particularly Plausibly). It was formatting correctly in .net but my DB was screwing with it. Had to change the user regional settings to British English! Doh! All fixed! Quote
Administrators PlausiblyDamp Posted February 3, 2004 Administrators Posted February 3, 2004 Always the simple things that catch us out ;) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.