Date and IIF

S

scubadiver

I have a date called A in 'date/time' format and I need a new date called B
based on A.

If the day of month is less than the 11th then N needs to be the 1st of the
month in A. If the day of month is 11th or later then it needs to be the 1st
of the next month.

At the moment I have the following and it is text format:

Month1: IIf(Format([detdate],"dd")<=10,"1/" & Format([detdate],"mm/yy"),"1/"
& (Format([detdate],"mm")+1) & "/" & (Format([detdate],"yy")))

I need it in 'date/time' format.

thanks!
 
D

Dave Peterson

Maybe...

Dim A as date
Dim B as date

'how does A get populated???
'test data
a = dateserial(2008,1,2) + timeserial(12,30,45)

if day(a) < 11 then
b = dateserial(year(a), month(a), 1)
else
b = dateserial(year(a), month(a) + 1, 1)
end if

or as one line:
B = DateSerial(Year(A), Month(A) - CBool(Day(A) > 10), 1)

What's N?



I have a date called A in 'date/time' format and I need a new date called B
based on A.

If the day of month is less than the 11th then N needs to be the 1st of the
month in A. If the day of month is 11th or later then it needs to be the 1st
of the next month.

At the moment I have the following and it is text format:

Month1: IIf(Format([detdate],"dd")<=10,"1/" & Format([detdate],"mm/yy"),"1/"
& (Format([detdate],"mm")+1) & "/" & (Format([detdate],"yy")))

I need it in 'date/time' format.

thanks!
 
K

Kevin B

I believe you were aiming for the Access forum and overshot your mark,
however, see if this works:

=Iif(Day([detdate])<=10,Dateserial(Year([detdate]),
month([detdate]),1),Dateserial(Year([detdate]), month([detdate]) + 1,1))

What it states is if the day of the month in the detdate field is <=10,
return the first day of the current month in the current year, otherwise
return the first day of next month in the current year.

Hopefully I've closed off all my parenthesis
 
S

scubadiver

I *was* looking for the Access forum, d'oh!

Kevin B said:
I believe you were aiming for the Access forum and overshot your mark,
however, see if this works:

=Iif(Day([detdate])<=10,Dateserial(Year([detdate]),
month([detdate]),1),Dateserial(Year([detdate]), month([detdate]) + 1,1))

What it states is if the day of the month in the detdate field is <=10,
return the first day of the current month in the current year, otherwise
return the first day of next month in the current year.

Hopefully I've closed off all my parenthesis
--
Kevin Backmann


scubadiver said:
I have a date called A in 'date/time' format and I need a new date called B
based on A.

If the day of month is less than the 11th then N needs to be the 1st of the
month in A. If the day of month is 11th or later then it needs to be the 1st
of the next month.

At the moment I have the following and it is text format:

Month1: IIf(Format([detdate],"dd")<=10,"1/" & Format([detdate],"mm/yy"),"1/"
& (Format([detdate],"mm")+1) & "/" & (Format([detdate],"yy")))

I need it in 'date/time' format.

thanks!
 
S

scubadiver

Thanks for that Kevin. It looks like it has worked.

Cheers!

Kevin B said:
I believe you were aiming for the Access forum and overshot your mark,
however, see if this works:

=Iif(Day([detdate])<=10,Dateserial(Year([detdate]),
month([detdate]),1),Dateserial(Year([detdate]), month([detdate]) + 1,1))

What it states is if the day of the month in the detdate field is <=10,
return the first day of the current month in the current year, otherwise
return the first day of next month in the current year.

Hopefully I've closed off all my parenthesis
--
Kevin Backmann


scubadiver said:
I have a date called A in 'date/time' format and I need a new date called B
based on A.

If the day of month is less than the 11th then N needs to be the 1st of the
month in A. If the day of month is 11th or later then it needs to be the 1st
of the next month.

At the moment I have the following and it is text format:

Month1: IIf(Format([detdate],"dd")<=10,"1/" & Format([detdate],"mm/yy"),"1/"
& (Format([detdate],"mm")+1) & "/" & (Format([detdate],"yy")))

I need it in 'date/time' format.

thanks!
 

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

Date function 2
Preserving date format 1
Excel Date 4
Weird date format problem 2
Conditional formatting of date-cell - 2007 5
date 2
date problem 4
Convert text date to mmddyyy date 2

Top