faroke moahmed
faroke moahmed

Reputation: 313

Splitting Date from DateTime

I need help on splitting the date from the below image file. Please help me to extract date alone. enter image description here

I had call this value in my grid view as..

date = c.transactionDate,

in my grid if i select today's date it display yesterday date..
enter image description here

My break Line display.. enter image description here

My Server Response date is correct..
enter image description here

Upvotes: 0

Views: 1961

Answers (2)

Sachin
Sachin

Reputation: 40970

You can get the Date part from the DateTIme object using Date property.

string datePart = c.transactionDate.Date.ToString();

If you want to show this value in your gridview column then you don't need to do this. You can directly use the DataFormatString property

<asp:BoundField DataField="TransactionDateField" HeaderText="Transaction Date" DataFormatString="{0:MM-dd-yyyy}"  />

Edit:

Your server date and the date which is displaying in the code both are same. As I guess your development machine is in IST time zone (+05:30) and the server is returning the time in time zone which is +11:00. So there is a difference of 05:30 hours in both time zone.

So when you see the time 2014-02-14T00:00:00:0+1100 in your code (VS). It gets converted into local time zone and display the value accordingly.

So above time zone gets subtracted by -05:30 hours to get in current time zone (IST) which is equivalent to 13:02-2014:06:30:00 PM

Upvotes: 2

BRAHIM Kamel
BRAHIM Kamel

Reputation: 13755

There is no dedicate pure Date class because you already have DateTime which can handle it. Having Date would lead to duplication and confusion.

use the Date property

c.transactionDate.Date 

if you want to show the date only just do something like this

DateTime date = DateTime.Now.Date;

 var pureDateOnly =  date.ToShortDateString();

Upvotes: 4

Related Questions