Problem calculating days

  • Thread starter Thread starter acs68
  • Start date Start date
A

acs68

Hi all,

When i calculate the below it is formatting the date as if it is American,
i.e mm/dd/yyyy. How do I get it to format so that it is in dd/mm/yyyy.

e.g if Me.txtDate is 30/09/2004, then I would get 91 days returned for
no_of_days

no_of_days = Me.txtDate - #1/7/2004#

I am attaching this code to a msgbox in an onclick event for a button

cheers,

Adam
 
acs68 said:
When i calculate the below it is formatting the date as if it is American,
i.e mm/dd/yyyy. How do I get it to format so that it is in dd/mm/yyyy.

e.g if Me.txtDate is 30/09/2004, then I would get 91 days returned for
no_of_days

no_of_days = Me.txtDate - #1/7/2004#

I am attaching this code to a msgbox in an onclick event for a button


The # signs specify that the enclosed characters are a date
in an unambiguous format. If there is a potential
ambiguity, then, by definition, it is in US format. You
must remember this whenever you use a date contsant in your
code or SQL. You can specify dates as #yyyy-mm-dd# if that
is more acceptable to you.

Note that the dates that a user enters in a form are
converted according to the Windows Local Settings so those
will be converted according to the user's preference. This
is also true for any dates you specify in your code using:
CDate("dd/mm/yyyy")
BUT, you have no idea what the user's setting may be so your
date can be something other than what you intended.

OTOH, it is almost always a Bad Programming Practice to
specify date constants in code. What are you going to do
next year, edit your code to keep it current??
 
Back
Top