Conditionally format Date/Time Values based on Time

Discussion in 'ASP .Net' started by dch3, Nov 9, 2008.

  1. dch3

    dch3 Guest

    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
    dch3, Nov 9, 2008
    #1
    1. Advertising

  2. 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:...
    > 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
    Nathan Sokalski, Nov 9, 2008
    #2
    1. Advertising

  3. dch3

    dch3 Guest

    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:...
    >
    > > 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
    >
    >
    dch3, Nov 9, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,137
    Janaka
    Feb 18, 2004
  2. Guest
    Replies:
    3
    Views:
    5,212
    Guest
    Jul 26, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,194
    Michael Borgwardt
    May 30, 2004
  4. Summu82
    Replies:
    5
    Views:
    847
    Richard Heathfield
    Jun 7, 2006
  5. David Pratt
    Replies:
    0
    Views:
    230
    David Pratt
    Oct 3, 2008
Loading...

Share This Page