DateAdd and Date Format at once

S

Silvio

I am trying to Add 6 months to [MyDate] field and format the result in Month
only

I know that Format([MyDate],"mmm") will show only the month

and

DateAdd("m",6,[MyDate]) will add 6 months to MyDate

But how I can not get both syntax work together?

This is what I have done but it does not work :-(
=Format((DateAdd("m",6,[MyDate]),"mmm"))

Thanks for the help folks.
 
J

Jeff Boyce

Silvio

"... does not work..." isn't particularly informative.

Does that mean nothing is displayed? ?You get an error message ... that
says what? Your PC locks up?

More info, please...

(aside from the doubled parentheses, I didn't notice anything about the
expression that caught my eye...)

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
S

Silvio

#Name Errror

Jeff Boyce said:
Silvio

"... does not work..." isn't particularly informative.

Does that mean nothing is displayed? ?You get an error message ... that
says what? Your PC locks up?

More info, please...

(aside from the doubled parentheses, I didn't notice anything about the
expression that caught my eye...)

Regards

Jeff Boyce
Microsoft Office/Access MVP

Silvio said:
I am trying to Add 6 months to [MyDate] field and format the result in
Month
only

I know that Format([MyDate],"mmm") will show only the month

and

DateAdd("m",6,[MyDate]) will add 6 months to MyDate

But how I can not get both syntax work together?

This is what I have done but it does not work :-(
=Format((DateAdd("m",6,[MyDate]),"mmm"))

Thanks for the help folks.
 
J

John Spencer (MVP)

That should work if MyDate is a datetime field in your table. You do have an
extra set of parentheses in what you posted and they are not in the correct
positions

Field: TheMonth: Format(DateAdd("m",6,[MyDate]),"mmm")

If you maintained what you had, you would need to move ,"mmm") so your
expression would look like:

=Format((DateAdd("m",6,[MyDate])),"mmm")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
D

Duane Hookom

Also, make sure the name of a control on your form or report is not the same
as the name of a field.

--
Duane Hookom
Microsoft Access MVP


John Spencer (MVP) said:
That should work if MyDate is a datetime field in your table. You do have an
extra set of parentheses in what you posted and they are not in the correct
positions

Field: TheMonth: Format(DateAdd("m",6,[MyDate]),"mmm")

If you maintained what you had, you would need to move ,"mmm") so your
expression would look like:

=Format((DateAdd("m",6,[MyDate])),"mmm")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I am trying to Add 6 months to [MyDate] field and format the result in Month
only

I know that Format([MyDate],"mmm") will show only the month

and

DateAdd("m",6,[MyDate]) will add 6 months to MyDate

But how I can not get both syntax work together?

This is what I have done but it does not work :-(
=Format((DateAdd("m",6,[MyDate]),"mmm"))

Thanks for the help folks.
 
S

Silvio

John, as usual you are THE man! If you don't mind I have one more question
regarding this, I am trying to compare MyDate to Date() to see if 6 months
have lapsed, if so then ...do whatever

Probably the format is NOT what I need, Guess should be DatePart???

..... If Format(MyDate, "m") >= Format(Date, "m") Then

In plain English: if OriginalDate + 6 months => The current Date then run
code...

The Day it's not important only the year and the month are.
e.g. something was done on January 13, 2009 the next time should be done any
time in July 2009 or later.


John Spencer (MVP) said:
That should work if MyDate is a datetime field in your table. You do have an
extra set of parentheses in what you posted and they are not in the correct
positions

Field: TheMonth: Format(DateAdd("m",6,[MyDate]),"mmm")

If you maintained what you had, you would need to move ,"mmm") so your
expression would look like:

=Format((DateAdd("m",6,[MyDate])),"mmm")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I am trying to Add 6 months to [MyDate] field and format the result in Month
only

I know that Format([MyDate],"mmm") will show only the month

and

DateAdd("m",6,[MyDate]) will add 6 months to MyDate

But how I can not get both syntax work together?

This is what I have done but it does not work :-(
=Format((DateAdd("m",6,[MyDate]),"mmm"))

Thanks for the help folks.
 
J

John Spencer (MVP)

You might use an expression like the following in a query.

IIF(DateSerial(Year(MyDate),Month(MyDate)+6,1) >= Date(), "Time to do
something","Chill Out")

OR Better use the datediff function
IIF DateDiff("m",MYDate,Date())>= 6,"Do Something","Chill out, man")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
John, as usual you are THE man! If you don't mind I have one more question
regarding this, I am trying to compare MyDate to Date() to see if 6 months
have lapsed, if so then ...do whatever

Probably the format is NOT what I need, Guess should be DatePart???

.... If Format(MyDate, "m") >= Format(Date, "m") Then

In plain English: if OriginalDate + 6 months => The current Date then run
code...

The Day it's not important only the year and the month are.
e.g. something was done on January 13, 2009 the next time should be done any
time in July 2009 or later.


John Spencer (MVP) said:
That should work if MyDate is a datetime field in your table. You do have an
extra set of parentheses in what you posted and they are not in the correct
positions

Field: TheMonth: Format(DateAdd("m",6,[MyDate]),"mmm")

If you maintained what you had, you would need to move ,"mmm") so your
expression would look like:

=Format((DateAdd("m",6,[MyDate])),"mmm")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I am trying to Add 6 months to [MyDate] field and format the result in Month
only

I know that Format([MyDate],"mmm") will show only the month

and

DateAdd("m",6,[MyDate]) will add 6 months to MyDate

But how I can not get both syntax work together?

This is what I have done but it does not work :-(
=Format((DateAdd("m",6,[MyDate]),"mmm"))

Thanks for the help folks.
 

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

Similar Threads


Top