Equivalent of date format

J

John

Hi

Is Format([Date],"yyyy/mm/dd") equivalent to Year([Date]) & "/" &
Month([Date]) & "/" & Day([Data]) ?

I am just wondering if using Year([Date]) & "/" & Month([Date]) & "/" &
Day([Data]) would be more sql server friendly for future upsizing.

Thanks

Regards
 
A

Allen Browne

Your Format() expression will yield different results from the concatenated
string in two cases:

a) If the date value is null, the Format() will yield Null whereas the
concatenated string will yield //

b) If the user's regional settings use a different date separator, Format()
will substitute that character, so, it could yield 2009.05.04 or 2009-05-04
etc. To force Format() to treat the / as literal, add a backslash before
it, i.e.:
Format([Date],"yyyy\/mm\/dd")

Of course, both forms yield a string (text data, not a Date type.) While you
certainly need to do this sometimes (e.g. to incorporate a literal date in a
SQL string), there are cases where leaving it as a Date/Time value would be
better. If you are creating a SQL string, filter, WhereCondition, criteria
argument, etc, you will want to include the # delimiter around the value,
i.e.:
Format([Date],"\#yyyy\/mm\/dd\#")

You should also be aware that if the date/time value does contain a time,
you're stripping the time value out with this expression.

And finally, if you have a field named Date, that will cause you grief in
Access. In some contexts, Access will misunderstand it for the system date;
in other contexts the SQL statement will fail because it's a reserved word
(though the square brackets around the name help avoid that.)

HTH
 

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