Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!!!

Posted

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?

  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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?

Posted

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?

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...