Conditionally format Date/Time Values based on Time

  • Thread starter Thread starter dch3
  • Start date Start date
D

dch3

Is there a way to conditionally format a dateTime field to produce on result
if the value is 10/31/2008 12:00 AM (user didn't enter a time) and another
result if the value is 10/31/2008 5:30 PM (user entered a time). I'm looking
for this result...

Value Result
10/31/2008 12:00 AM FRI 10/31/08
10/31/2008 12:01 AM FRI 10/31/08 12:01 AM

I also need to figure out the cell spacing to force the time onto a
different line as in

10/31/2008 12:01 AM FRI 10/31/08
12:01 AM

David H
 
I'm guessing you would probably do it the same way as any other conditional
statement, where the conditional determines the format string to use. What
you will use as the condition may be a little tricky, since it is obviously
quite possible for the user to enter a time of 12:00 AM, so looking at the
time entered would not be enough to determine whether a time was entered.
How you will apply the format string will depend on where you are displaying
the date and possibly a time. If it is simply a TextBox or Label or some
other control with just a simple Text property, you can just use the
DateTime.ToString(formatstring) method. If you are using a databound control
such as a Repeater or DataList, you may need to do it in the ItemDataBound
event. I'm not going to get into details of what you should do, since I
haven't seen your code, but hopefully this can get you started. Good Luck!
 
A field from a database displayed in a GridView. My experience is with
Classic ASP. I just started playing with ASP.NET tonight. (Damn I wish I had
tried this sooner)
 
Back
Top