Click here to Skip to main content
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 22: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 OriginalGriff 467
1 CPallini 400
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 254
4 George Jonsson 251
0 OriginalGriff 5,370
1 CPallini 4,360
2 Sergey Alexandrovich Kryukov 3,822
3 George Jonsson 3,037
4 Gihan Liyanage 2,435


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
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