Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date only

Status
Not open for further replies.

arniebarnie

Programmer
Sep 26, 2003
3
NL

I have a DateTimePicker in a form, of which i only want the date value.
I keep getting the date AND the time!
Can anybody help me?
 
>> I keep getting the date AND the time!

Post the code

-pete
 
You are probably just asking for the wrong property. For instance, if you are accessing the "Text" property, you will get the date and time as a string. If you want the date as a string, you could access it like this:

dateTimePicker1.Value.ToShortDateString();

If you want other formats/values/etc. just check out the methods and properties on the DateTime class (which is the type of the DateTimePicker.Value property). You will find what you want.
 
you're right, i haven't explained the problem correctly.
I get the right value, fine. But then i put it into a dataset, in a System.DateTime field and then when i want to get the value from it again, i can only access it using the toString method.
 
Hi,
The date you put in DataSet is more exactly in DataTable object that belongs of the DataSet. The DataTable objects contains Rows and Columns collections. So,
-every column is represented by a DataColumn object.
- the date you put in the DataTable object is defined by a DataColumn object with values stored in the DataRow objects. If the type of data of the column is System.DateTime then it is keept as DateTime but you will extract it from a DataRow object object using an indexer function and after that various Format functions .

Let be ExpirationDate the name of the column and dr a DataRow object.
object obj = dr["ExpirationDate"] is an Object object that contains the data.
Now, (DateTime)obj.
ToString("yyyy/MM/dd", System.Globalization.DateTimeFormatInfo.InvariantInfo) ;
or another format.

-obislavu-



 
I'm a bit baffled by this same problem and don't understand the solutions posted so far. I have a datatable in a dataset with a field named Birthday which uses the date type(not datetime). I have a textbox on a form that has databinding/text property set to the Birthday field in my datatable. Whether I pull data into the datatable using a datadapter or fill in the date myself using the form it instantly pops up as the correct date followed by 12:00. Am I missing something? At what point do you format the value?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top