Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Breaking date down into component parts

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
US
I need to take the system date and break it down into a 2-digit month value and a 2-digit year value in Access 2000 and use them as the default values for new entries to a table.

I have tried to get the year value thus:
[tt]
Format(DateSerial(Year(Date()),Month(Date()),Day(Date())),"yy")
Format(Date(),"yy")
Right(DateValue(Date()), 2)
Right(Format(Date(),"mmddyy"),2)
Year(Date())
[/tt]
all resulting in "#Error" in the new record field.

Can anyone suggest something else, or spot the error in one of the above?

Cheryl dc Kern
 
I'm unclear as to the ultimate goal is, but I think you want the Datepart function.

--Lilliabeth
 
Is the field text or numeric? You should be able to set the default of a text field in a table to:
[tt][blue]
Default Value: =Format(Date(),"mmyy")
[/blue][/tt]

Duane
Hook'D on Access
MS Access MVP
 
The field is text. I need only the year for one field, only the month for another. So if today's date is 12/30/09, I need 09 for the year field and 12 for the month.
Once again, the devil is in the details. I missed the "=".

Thank you!

Cheryl dc Kern
 
All fixed now. Thanks again.

Cheryl dc Kern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top