• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

ASP.NET European date VERY WEIRD PROBLEM

I am designing an ASP.net app for UK - so need the date format dd/mm/yyyy.

My development machine is setup for UK in control panel - and so is the registry (in as dd/mm/yyyy).

When I use
System.DateTime.Now.Date.ToString()
it outputs in dd/mm/yyyy format. When I go into sql server enterprise manager - it outputs in dd/mm/yyyy format.

When I attempt to run a ExecuteNonQuery on a sql server database however, it fails unless the date is in US format?!?!!?

So PLEASE if anyone knows why - help!

Firstly is there a quick workaround that will change the System.DateTime.Now.Date.ToString() date to US format - and secondly and more importantly - how can i get the ExecuteNonQuery to take UK date format?

I have been banging my head against a wall for days - any ideas?
0
niico
Asked:
niico
1 Solution
 
CJ_SCommented:
You will also need to set the correct date / language format of SQL Server. Do this in the properties of the SQL Server machine.

Another way to get the correct date format in SQL Server is by using the SET DATEFORMAT.

Example:
SET DATEFORMAT dmy
SELECT GETDATE()

(change SELECT GETDATE() with any query you want)

CJ


0
 
Michel SakrCommented:
try the convert function in sql
0
 
smeggheadCommented:
when you pass the SQL string into SQL Server, you should pass it in the format yyyy-mm-dd, this is a locale independant format.
0
 
niicoAuthor Commented:
hmm some interesting suggestions - i have ended up going for a simple conversion function that converts from uk date format into us date format - as the sql query engine always needs US format i have read.
0
 
niicoAuthor Commented:
thanks everyone - i guess this is the most useful answer to me!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now