DateTime dt=Convert.ToDateTime(data);
if ((dt.Year == DateTime.Now.Year)
&& (dt.Month == DateTime.Now.Month)
&& (dt.Day == DateTime.Now.Day))
lblDate.Text = "Today";
This code too lazy
For the first question:
In general:
if (first.Date == second.Date)
To check whether a DateTime
is "today"
if (dateTime.Date == DateTime.Today)
Note that this doesn't take any time zone issues into consideration... What do you want to happen if the other DateTime
is in UTC, for example?
I'm not sure what you mean by the second question. Could you elaborate? You can do:
TimeSpan difference = first - second;
if that's any help... look at the TimeSpan
documentation for more information about what's available. For instance, you may mean:
double minutes = (first - second).TotalMinutes;
but you may not...
1. DateTime.Equals(DateTime dt1, DateTime dt2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With