Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Conditionally format Date/Time Values based on Time (http://www.velocityreviews.com/forums/t643658-conditionally-format-date-time-values-based-on-time.html)

dch3 11-09-2008 03:25 AM

Conditionally format Date/Time Values based on Time
 
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 11-09-2008 03:55 AM

Re: Conditionally format Date/Time Values based on Time
 
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
njsokalski@hotmail.com
http://www.nathansokalski.com/

"dch3" <dch3@discussions.microsoft.com> wrote in message
news:A52CB169-710C-4321-92B0-6FB7AD953F39@microsoft.com...
> 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 11-09-2008 04:03 AM

Re: Conditionally format Date/Time Values based on Time
 
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" <dch3@discussions.microsoft.com> wrote in message
> news:A52CB169-710C-4321-92B0-6FB7AD953F39@microsoft.com...
>
> > 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
>
>



All times are GMT. The time now is 08:44 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.