Click here to Skip to main content
11,410,118 members (52,958 online)
Rate this: bad
good
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 at 22-Jan-13 5:01am
   
Do not store dates as text. SQL has a DateTime type specifically for storing such values.
vinayak chavan at 22-Jan-13 5:03am
   
yer dear i have taken datatype-- datetime in sql
vinayak chavan at 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
Smile | :)
  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
0 Sergey Alexandrovich Kryukov 219
1 Maciej Los 128
2 OriginalGriff 120
3 Sascha Lefévre 120
4 BillWoodruff 60
0 Sergey Alexandrovich Kryukov 8,771
1 OriginalGriff 6,905
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2015
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