My Assistant
![]() ![]() |
|
|
Jan 28 2010, 05:27 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 110 From: Idaho |
Does any one know how I can format a date that currently displays as 12/31/1975 as 31st December 1975?
|
|
|
|
Jan 28 2010, 05:49 PM
Post
#2
|
|
|
UA Editor + Utterly Certified Posts: 22,726 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Try format function: ? Format(#12/31/1975#,"dd mmmm yyyy") 31 December 1975 HTH's (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Jan 28 2010, 05:59 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 110 From: Idaho |
got that part.... I want to cantonate the proper suffix to the day ie: 31 st 22 nd 13 th
|
|
|
|
Jan 28 2010, 06:02 PM
Post
#4
|
|
|
UtterAccess Guru Posts: 630 From: Ottawa, Ontario, Canada |
Here's a function that should do it.
CODE '--------------------------------------------------------------------------------------- ' Procedure : dateOrd ' Author : Jack ' Created : 1/28/2010 ' Purpose : To format a date into day (ordiinal) full Month and 4 digit year. ' ' Example: 31/12/1975 gives 31st December 1975 ' 15/10/2003 gives 15th October 2003 '--------------------------------------------------------------------------------------- ' Last Modified: ' ' Inputs: A valid date ' Dependency: N/A '------------------------------------------------------------------------------ ' Function dateOrd(d1 As Date) As String Dim i As Integer Dim ret As String Dim s As String On Error GoTo dateOrd_Error s = Format(d1, " MMMM YYYY") i = Format(d1, "dd") Select Case i Case i = 1 Or 21 Or 31 sufx = "st" Case i = 2 Or 22 sufx = "nd" Case i = 3 Or 23 sufx = "rd" Case Else sufx = "th" End Select dateOrd = i & sufx & s 'Debug.Print ret On Error GoTo 0 Exit Function dateOrd_Error: MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure dateOrd" End Function HTH |
|
|
|
Jan 28 2010, 06:05 PM
Post
#5
|
|
|
UtterAccess Addict Posts: 110 From: Idaho |
you all are the best
|
|
|
|
Jan 28 2010, 06:09 PM
Post
#6
|
|
|
UA Editor + Utterly Certified Posts: 22,726 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Also anther one...: CODE Function formatday(dtDate) As String Dim dtDay As Long dtDay = CLng(Day(dtDate)) Select Case dtDay Case Is = 1, 21, 31 formatday = dtDay & "st" Case Is = 3, 23 formatday = dtDay & "rd" Case Is = 2, 22 formatday = dtDay & "nd" Case Else formatday = dtDay & "th" End Select End Function Example: ? FormatDay(#12/31/1975#)& Format(#12/31/1975#," mmmm yyyy") 31st December 1975 HTH's (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Jan 28 2010, 09:25 PM
Post
#7
|
|
|
Retired Moderator Posts: 19,667 |
Another variation that returns the whole date in the required format:
CODE Public Function FormatOrdinalDay(ByVal dtDate As Date) As String Dim intDay As Integer intDay = Day(dtDate) If (intDay >= 10) And (intDay <= 20) Then FormatOrdinalDay = Format(dtDate, "d\t\h mmmm yyyy") Else Select Case intDay Mod 10 Case 1 FormatOrdinalDay = Format(dtDate, "d\s\t mmmm yyyy") Case 2 FormatOrdinalDay = Format(dtDate, "d\n\d mmmm yyyy") Case 3 FormatOrdinalDay = Format(dtDate, "d\r\d mmmm yyyy") Case Else FormatOrdinalDay = Format(dtDate, "d\t\h mmmm yyyy") End Select End If End Function From the Immediate window: ?FormatOrdinalDay(#12/31/1975#) 31st December 1975 |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 20th June 2013 - 06:54 AM |