Connecting Tech Pros Worldwide Forums | Help | Site Map

change date format to 'Morning', 'Noon' and 'Afternoon'

Newbie
 
Join Date: Dec 2007
Posts: 4
#1: Dec 18 '07
Hi,

I'm sure this has been done before, but I can't seem to find this one on the net....

I have a datefield but instead of it just displaying:

07/12/18 08:30

I would like to display it as: 07/12/18 MORNING

or when it's 07/12/18 12:00 as: 07/12/18 NOON

and 07/12/18 14:30 as: 07/12/18 AFTERNOON

From 00:00 till 11:30 = MORNING
from 11:30 till 13:30 = NOON
from 13:30 till 17:00 = AFTERNOON

Can someone plz help me with this?

Thanks alot in advance!

Joachim

QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#2: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Hi,

Extract the TimePart from the Date, Use a "Select Case" or "IF" condtion to print the Day Part..

REgards
Veena
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#3: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


You simply need to extract the time part only anc compare as per youir range and display accordingly.
Newbie
 
Join Date: Dec 2007
Posts: 4
#4: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Quote:

Originally Posted by QVeen72

Hi,

Extract the TimePart from the Date, Use a "Select Case" or "IF" condtion to print the Day Part..

REgards
Veena

This is what I have:

Expand|Select|Wrap|Line Numbers
  1. Function Value
  2.  
  3.    If Not IsNull(DeadLine) Then
  4.       If TimeValue(DeadLine) = 0 Then
  5.          Value = Format(DeadLine, "dd/mm/yyyy")
  6.       Else
  7.          If DateValue(DeadLine) = 0 Then
  8.             Value = Format(DeadLine, "hh:mm")
  9.          Else
  10.             Value = Format(DeadLine, "dd/mm/yyyy, hh:mm")
  11.          End If
  12.          Value = Value & " uur"
  13.      End If
  14.      Value = Value
  15.    End If
  16.  
  17.    If Not IsNull(Me.EstimatedTime) Then
  18.       If Value > "" Then
  19.          Value = Value & ", "
  20.       End If
  21.       Value = Value & "duur ca." & Format(Me.EstimatedTime, "0.0#") & " uur."
  22.    End If
  23.  
  24. End Function


So I want to take the hour from this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Function TimeOfDay()
  3.    If TimeValue(Me.EstimatedTime()) < 11 Then
  4.       TimeOfDay = "Voormiddag"
  5.    End if
  6.  
  7.    If TimeValue(Me.EstimatedTime()) =>11 AND TimeValue(Me.EstimatedTime()) < 13 Then
  8.       TimeOfDay = "Middag"
  9.    End if
  10.  
  11.    If TimeValue(Me.EstimatedTime()) => 13 Then
  12.       TimeOfDay = "Namiddag"
  13.    End if
  14. End Function

But it doesn't work ....

Can you help me plz?
Thanks.
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#5: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


you need to capture only the hour from time part in 24 hrs format and compare the same in a simple select case and display as desired.
Newbie
 
Join Date: Dec 2007
Posts: 4
#6: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Quote:

Originally Posted by debasisdas

you need to capture only the hour from time part in 24 hrs format and compare the same in a simple select case and display as desired.

Sorry, but i'm a real newbie.

Can you help me with the code please?

Thanks ....
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#7: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Hi,

Dont Use, TimeValue ...

Use Hour(MyDate) in your TimeOfDay function..

REgards
Veena
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#8: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Do not post duplicate threads or send PM to anyone it is strictly against forum rules. Do as sugested by our expert in the previous post.
Newbie
 
Join Date: Dec 2007
Posts: 4
#9: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Quote:

Originally Posted by QVeen72

Hi,

Dont Use, TimeValue ...

Use Hour(MyDate) in your TimeOfDay function..

REgards
Veena

Thank you so much! It works!! :)
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#10: Dec 18 '07

re: change date format to 'Morning', 'Noon' and 'Afternoon'


Quote:

Originally Posted by debasisdas

Do not ... send PM to anyone it is strictly against forum rules

This is a valid point, but comes across in this post as a slight exaggeration. I'd just like to clarify.

It is not "strictly against forum rules" to send anyone a PM. Private Messages are often used to chat "off list" to avoid cluttering up the discussion forum. But for technical questions and answers we want everything in the forum so it's available for later reference. TheScripts is all about the free exchange of information, so discussing these things in private goes against that ideal.
Reply