Last post Nov 12, 2008 08:15 AM by Omkar Lale
Nov 10, 2008 06:04 AM|zarstylei|LINK
I have a textbox which user types in the date in UK format & then inserts it into the sql database where the field date is in UK format. If I type-in 11/11/2008, it's ok, but if I type-in 27/11/2008, an error occurs. And it seems from the web form, it is
inserting the MM/dd/yyyy format, that's why it's creating an error if the 1st date element is greater than 12.
I have tried declaring <% Page Culture="en-GB" ....., but did not worked. I also put this code:
uiCulture="en-GB" /> in the web.config to no avail.
I have also put this code in the button click event:
Dim ukCulture As Globalization.CultureInfo = New Globalization.CultureInfo("en-GB")
Dim myDateTime As DateTime
myDateTime = DateTime.ParseExact(Me.txtDateofEvent.Text, "dd/MM/yyyy", ukCulture.DateTimeFormat)
Me.txtDateofEvent.Text = myDateTime.ToString("dd/MM/yyyy")
This didn't work as well.
I'll appreciate it very much if you can solve this for me. Cheers!
Nov 10, 2008 09:48 AM|adyNET|LINK
SQL Server runs on the windows region, if you change your regional settings of your windows, it will allow you to enter the UK format into database, however, in your case I would store the US format in database and then in web.config i would define the
cultureinfo of the application and it automatically converts all datetime/calendar according to the culture format in the web.config
Please mark this post as answer if it has helped you.
Nov 12, 2008 06:53 AM|zarstylei|LINK
Thanks adyNET for ur reply! I have to consider that most of the machines & server in UK do have the regional setting to en-GB & I'm afraid I can't adopt ur suggestion if I published this to another server.
Can this be hand-coded instead? Any more advice, pleeeeeeeeeaaaasse?
Nov 12, 2008 08:15 AM|Omkar Lale|LINK
Try out with yyyy-MM-dd format to insert the date in database.