Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
First, I insert a date with control "datepicker", then when I want to modify some data I dont want to change the date it will change automatically to the default value which is 01/01/1990 00:00:00.

Problem is that I don't want to display the time only date.
Posted
Updated 19-Aug-14 9:11am
v2
Comments
sagivasan 19-Aug-14 10:30am    
use cultureInfo
M-osab 19-Aug-14 10:41am    
can you explain a little more plz
[no name] 19-Aug-14 10:49am    
Which of those three things is the actual problem and what does any of that have to do with the code that you have written?
M-osab 19-Aug-14 10:59am    
I want to update in database only the date when i change datepicker value,
Sergey Alexandrovich Kryukov 19-Aug-14 12:06pm    
Not clear.
—SA

1.
CultureInfo newCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.DateSeparator = "/";
Thread.CurrentThread.CurrentCulture = newCulture;


2.

DateTime myDate = new DateTime();
   string us = myDate.ToString(new CultureInfo("en-US"));
 
Share this answer
 
Since you're a newbie you first need to understand what a DateTime object is and what a date time picker object would return to you, it is a string not a DateTime.

You need to convert it to the DateTime object and then you can do the DateTime maths on it.

     | in the first time I insert a date with control "datepicker",

for that you need to get a date time picker object, and pass a valid string to it or select from the UI provided.

     | in the second time when i want to modify some data and i dont want to change the date it will change automatically to the default value which is 01/01/1990 00:00:00

To change it automatically, you can simply just create a new instance, and it will go back to the Min value of the DateTime, like this

C#
DateTime dateTime = new DateTime(); // there you go!


Once done, you can get the Date part using a built-in function like

C#
MessageBox.Show(dateTime.ToLongDateString());


It will show you with the date part of the dateTime object only.

I have written an article about the DateTime object and how you can use it in WPF, Understanding DateTime struct in .NET Framework (using C#)[^] feel free to read it and ask question if help needed! :-) Good luck.
 
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