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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting part of a date 2

Status
Not open for further replies.

Apollo13a

Technical User
Apr 27, 2003
277
US
Hi, I'm trying to set a date variable equal to just the year of my returned date.
Code:
some DAO to get the date info then

LaborYear = !LaborDate
  LaborYear = DatePart("yyyy", !Labordate)
My code gets the proper date but I'm having trouble extracting the year Can someone point me in the right direction.

Jim
 
Well, it seems I've found a solution but I'm wondering if it is the best way to go. I changed the data type of LaborYear to string and then using
Code:
LaborYear = Format(!LaborDate, "yyyy")

i get just the year

jim
 
try making the variable a string instead of a date.

Code:
Dim sLaborYear as string

sLaborYear = Datepart("yyyy", !LaborDate)
Msgbox sLaborYear
 
Why not make it an integer and use,

intLabourYear = Year(!LabourDate)
 
It depends what are you trying to do. Why do you need a variable with the year value? You already know the year why do you need to store it as a variable? The solutions above may work. You have solutions that produce a string or an integer, but none are a "year". So you may find that you need to convert back to do any type of calculations or comparisons. Remember regardless of how a date is displayed all dates and times are stored the same way.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top