Mix custom and default date format

C

Carl Colijn

Hi all,

In my date/time fields on my forms I would like to use a combination of a
standard date format and another standard time format. To be specific, I
would like to use a combination of the Short date format and the Short time
format.

I could just use my own formatting, like e.g. "d/m/yyyy hh:nn", but then I
lose regional settings support (because I hardcoded the day/month order).
However, I read in the help files that the format code "c" uses the standard
date format, but the time component of this format shows the seconds which I
want to leave out... I suspect the other standard formats have no build-in
code I can use? Or is there another alternative?

Thanks in advance,
Carl Colijn

--
TwoLogs - IT Services and Product Development
A natural choice!
http://www.twologs.com
TimeTraces: the powerfull and versatile time registration system!
http://www.twologs.com/en/products/timetraces.asp
 
T

TC

I use a simple trick to determine the PC's date format, without messing
around with the system-locale APIs:

if month(cdate("1/2/2006")) = 1 then
' month/day format.
else
' day/month format !
endif

I have a procedure which is passed a control from a form or report. The
procedure uses that trick to construct a new date format of my choice,
but obeying the user's day/month versus month/day format. Then it sets
that format onto the passed control. Every form & report calls this
procedure, from its Open or Load event, for each date control on that
form or report.

Voila: formats that work the way /you/ want, but also, obey the user's
international date settings.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
T

TC

PS. In case it's not obvious: the test date can be hard-coded. It does
not matter what it is, as long as the day and month numbers are
different, *and*, each of those numbers would be accetable as a day
*or* a month.

TC
 
C

Carl Colijn

In
TC said:
PS. In case it's not obvious: the test date can be hard-coded. It does
not matter what it is, as long as the day and month numbers are
different, *and*, each of those numbers would be accetable as a day
*or* a month.

TC

Hi TC,

Great solution! Simple and powerfull, just the way I like it ;) Although
I'd do the test only once in the entire DB's execution time to save some
cycles; you're dealing with a perfectionist here :)

I'll use something like the following in a module:

Private m_sCustomDateTime As String
Private m_bCustomDateTimeAssigned As Boolean

Public Function g_csCustomDateTime() As String
If Not m_bCustomDateTimeAssigned Then
If Month(CDate("1/2/2006")) = 1 Then
m_sCustomDateTime = "m/d/yyyy h:nn"
Else
m_sCustomDateTime = "d/m/yyyy h:nn"
End If
m_bCustomDateTimeAssigned = True
End If
g_csCustomDateTime = m_sCustomDateTime
End Function

Thanks again,
Carl
 
T

TC

Carl said:
Although I'd do the test only once in the entire DB's execution
time to save some cycles; you're dealing with a perfectionist here :)

Well, we are clearly of a like mind!

My procedure saves the calculated format into a local static variable.

Cheers,
TC (MVP Access)
http://tc2.atspace.com
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top