Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have a field of date which has datetime datatype but the insertion is not done.

because it try to insert in dd/MM/yyyy formate. so how can i insert the current date as MM/dd/yyyy in database.

Please Help me...

Thanks and Regards...
MItesh
Posted
Comments
Kenneth Haugland 21-Jul-12 5:29am    
IS it SQL or Accsess? In any rate I have had the same problem, and solved it by sending the date with American culture, as is the default...
[no name] 21-Jul-12 5:33am    
SQL SERVER
[no name] 21-Jul-12 5:36am    
how can i send or set the time as american culture

hii,
solution 1:


using datetime object you will get dd mm yyyy format. need to convert it into string using .tostring("MM/dd/yyyy") and then insert it.
for e.g

string date=DateTime.now.ToString("MM/dd/yyyy");

update tableName set date=@date (in database)

it will work.
 
Share this answer
 
Comments
André Kraak 21-Jul-12 5:52am    
If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution.
Thank you.
[no name] 21-Jul-12 6:15am    
Thanks Ganesh, it works... Thanks a Lot... nice help yarrrrrrr. I am very confuse about it but your Solution help a lot.... Thanks Again
[no name] 21-Jul-12 6:15am    
my 5+++++
You need to store dates using the DateTime object, both in your code, and in your database. If you're getting a date time as a string, you can use DateTime.TryParse and specify the format the date is in, in order to get it in to a DateTime. You can use DateTime.ToString to turn a date in to a string in the format you want to see. NEVER store or work with dates as strings, it's bad.

Your core issue is probably a localisation setting in your DB, but if you use datetimes, it won't matter.
 
Share this answer
 
Comments
[no name] 21-Jul-12 5:30am    
it is possible to convert the current date formate in MM/dd/yyyy. because my system contain the dd/MM/yyyy. so then i able to insrt into database
Christian Graus 21-Jul-12 5:32am    
Only an idiot deals with date times as strings. Convert it to a DateTime. You can set your system settings to be for the US, I assume you're outside the US and working for a US client. I do the same, every day. But, because my code is written correctly, it just works, without having to set my system to be MM/dd/YYYY.
[no name] 21-Jul-12 5:35am    
when i try to insert current time as.

datetime.Now .. it does not insert into db. because it consist as 21/07/2012. and 21 as Month not day
Christian Graus 21-Jul-12 5:39am    
This makes zero sense. A DateTime does not have a format, it has properties for month and day. You're talking about the rendering details of a string and I am saying, don't use a string.
[no name] 21-Jul-12 5:42am    
but it does not insert into the database as Datetime.Now

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