Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
cmd.Parameters.AddWithValue("Date", VdateTimePicker1.Value.ToString("dd/mm/yyyy h:mm:ss tt"));

i am using above code but not working.
Posted

1 solution

Don't.

Seriously, don't.
The only way to store a date anywhere with an AM/PM indicator is to store it as a string - and that's a very poor idea. The trouble is that it means the data must be re-evaluated and converted to a date each time you want to use it - which means it's very easy for the wrong data (different format, bad dates, usernames instead of dates) to get into the database and very difficult to sort it out later because it causes your app(s) to crash only when they try to use it.

Store them as a DATETIME value, send them as a DateTime parameter and it all sorts itself out. If you need to display them with an AM/PM indicator when you later present them to the user in some form, then format them then - because you can present them in a format that is relevant to that user (which may be different to the format the user sitting next to him expects).

Then your code just becomes:
C#
cmd.Parameters.AddWithValue("Date", VdateTimePicker1.Value);
 
Share this answer
 

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