Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Conditionally format Date/Time Values based on Time

Reply
Thread Tools

Conditionally format Date/Time Values based on Time

 
 
dch3
Guest
Posts: n/a
 
      11-09-2008
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
 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      11-09-2008
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!
--
Nathan Sokalski

http://www.nathansokalski.com/

"dch3" <> wrote in message
news:A52CB169-710C-4321-92B0-...
> 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



 
Reply With Quote
 
 
 
 
dch3
Guest
Posts: n/a
 
      11-09-2008
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)

"Mark Rae [MVP]" wrote:

> "dch3" <> wrote in message
> news:A52CB169-710C-4321-92B0-...
>
> > Is there a way to conditionally format a dateTime field

>
> A dateTime field...?
>
> The formats you are looking for are simple enough to achieve in code - how
> exactly that is done in practice will depend what you mean by a dateTime
> field. Are you talking about a column in a GridView, a TextBox, a Label...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditionally subclassing based on Import David Pratt Python 0 10-03-2008 06:45 AM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
covert time from date Hour min sec format to epoch time i.e time since 1 jan 1970 in C Summu82 C Programming 5 06-07-2006 02:51 PM
ASP.NET: How to conditionally display content based on login/authentication? ASP .Net 3 07-26-2005 08:58 PM
Format textbox to time format ruca ASP .Net Web Controls 1 05-09-2005 05:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57