Click here to Skip to main content
12,621,191 members (36,484 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
i have datetimepicker on form

i need date stored in database in this manner --2013-01-22 00:00:00.000

but when user make the entry it save like--2013-01-21 14:58:00.000

How can i resolved this issue??
Posted 21-Jan-13 23:56pm
Comments
Richard MacCutchan 22-Jan-13 5:01am
   
Do not store dates as text. SQL has a DateTime type specifically for storing such values.
vinayak chavan 22-Jan-13 5:03am
   
yer dear i have taken datatype-- datetime in sql
vinayak chavan 22-Jan-13 5:08am
   
cmd.Parameters.AddWithValue("Date", dateTimePicker1.Value.ToString());
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Cast your datetime variable with ToShortDateString so you can eliminate the time part from your datetime varible.

Please let me know if you are looking for this.

Happy Programming
:)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try this....
DateTime dt = new DateTime();
          string lstrDate = "2013-01-21 14:58:00.000";
          dt = Convert.ToDateTime(lstrDate);
          string lstrADate = dt.ToString("yyyy-MM-dd");

Use lstrAData variable value to store in the database...
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

HI,

Use the following link for parsing and formating any date format.

Different date formats

Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100