Recieving the Year from the Date() function

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

What I am doing is this:

For a primary key in one of my tables, I am using the
current year. So, what I do is take the Year(Now) value
and put into a string. However, I am not interesting in
the entire "2004", I am only interested in the "04". Is
there anyway I can take a string and extract the last two
characters from it?

For example:

strString = str(Year(Now))
'strString = "2004"
newString = SomeFunction(strString, 2)
'newString = "04"



Any help would be appreciated.
 
Mike said:
What I am doing is this:

For a primary key in one of my tables, I am using the
current year. So, what I do is take the Year(Now) value
and put into a string. However, I am not interesting in
the entire "2004", I am only interested in the "04". Is
there anyway I can take a string and extract the last two
characters from it?

For example:

strString = str(Year(Now))
'strString = "2004"
newString = SomeFunction(strString, 2)
'newString = "04"


You can use the Right function to get the last two
characters in a string:

newString = Right(strString, 2)

But this is the long way around. You can do the whole job
with:

newstring = Format(Date, "yy")
 
Back
Top