Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
When inserting query using now() function it is throwing DD/MM/YYYY but need to send MM/DD/YYYY to database.


It is happen in windows server 2012.

What i am thinking time zone problem but where i need to change i am not getting give some solution.
Posted
Updated 4-Dec-13 2:59am
v2
Comments
Mike Meinz 4-Dec-13 9:52am    
You don't show any code so we have no way of knowing exactly what you mean by "inserting query using now() function".

1. Dates and Times should be stored in database columns that are of DateTime Data Type.
2. Values should be passed to the SQL Server using the SQLParameter class. This prevents SQL Injection Attacks, improves performance and properly handles Date and Time data types.

Don't format dates before sending them to a database: send them via a parameterised query as a DateTime object (as DateTime.Now returns) and store it in the DB as a DateTime column.
That way, you can do comparisons on it and everything will just work. You should only format dates when you actually need to present them to the user, and you should be using his prefered display format then anyway.
 
Share this answer
 
Comments
Maciej Los 4-Dec-13 10:52am    
Nothing to add ;)
+5!
nane aa 5-Dec-13 1:04am    
I am configured same application in another system it coming properly MM/DD/YYYY.
But in my server only getting like DD/MM/YYYY.
OriginalGriff 5-Dec-13 3:41am    
That's because you are using strings, instead of DateTime values. Don't.
Show the actual code that generate the error you see (i.e. how you actually know that there is a problem, not the code you think is creating the problem)
Use below lines of code to format the date.
DateTime time = DateTime.Now;
time.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

also check below link for more information

http://stackoverflow.com/questions/18595758/date-format-conversion-in-c-sharp[^]
 
Share this answer
 
Comments
nane aa 5-Dec-13 1:04am    
I am configured same application in another system it coming properly MM/DD/YYYY.
But in my server only getting like DD/MM/YYYY.

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