Problem calculating days

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
 
M

Marshall Barton

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??
 

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