working with date() and datepart

  • Thread starter Thread starter Karen
  • Start date Start date
K

Karen

I want to display our current lot number on a form so users don't have to
run to a calendar to figure it out. It's really simple. We use the week
number, =format(now(),"ww") , plus the last two digits of the current year
(04). How do I get 04 instead of 2004? I can only find the datepart
function and it only does the full year.

Karen
 
You should be careful with your use of now() in place of date()

You can use now() in your case..but should be using date.

While often the difference between now() and date is none, in many cases the
difference is HUGE.

if you set a date field to now(), the now() function includes both the date
+ time.

If you did not intend to save the time portion..then any query you use to
test for today's date will NOT work for that field value. You have to
include both the date and the time in your query. So, use extreme caution
with the now() function..as it does include a time portion..and thus any
date code or query that you use for dates will need to include the time
portion. I seen people use now() as value setting for a field..and then ask
why their date queryes don't work.....you can make a mess of a whole
database by accidnelty using now() in place of date(). If you need a date
value...use date(). If you need both date + time values...then use now().

Ok..now..lets get to your question:
I want to display our current lot number on a form so users don't have to
run to a calendar to figure it out. It's really simple. We use the week
number, =format(now(),"ww") , plus the last two digits of the current year
(04). How do I get 04 instead of 2004? I can only find the datepart
function and it only does the full year.

Try:

=( formate(date(),"ww") & format(date(),"YY") )
 
You may be able to use MID function to get the last 2
digits.

MID(DATEPART("YYYY",DATE()),3,2)
 
Thank Albert. That works. I wasn't getting the bit about the format.

I usually use date() but in the help file where I found the example of
displaying the week, it showed now() so i used it in my example. I did use
now() in my first access database that i developed. I learned my lesson
when i had to go and find all of them and change them to date.
 
good on you

;-) pieter

Karen said:
Thank Albert. That works. I wasn't getting the bit about the format.

I usually use date() but in the help file where I found the example of
displaying the week, it showed now() so i used it in my example. I did use
now() in my first access database that i developed. I learned my lesson
when i had to go and find all of them and change them to date.
 
Back
Top