Date Serial for 12 months ago? (1 Viewer)

gojets1721

Registered User.
Local time
Today, 02:21
Joined
Jun 11, 2019
Messages
430
I was hoping to use a dateserial function to produce a date that is 12 months prior to today's date.

So if today is 11/10/2022, then the date serial function would show 11/11/2021. Basically exactly 365 days prior.

Any suggestions?
 

plog

Banishment Pending
Local time
Today, 04:21
Joined
May 11, 2011
Messages
11,653
Basically exactly 365 days prior.

Basically exactly? That's some fine wordsmithing.

You would literally figuratively use DateAdd, not DateSerial:


Be careful when you cross over leap days--what basically exactly do you want for 12 months/365 days prior to 3/3/2024? Pretty sure -12 months produces a different result than -365 days.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:21
Joined
May 21, 2018
Messages
8,554
Datesserial(year(date),month(date),day(date)-1)
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:21
Joined
May 21, 2018
Messages
8,554
FYI. The date serial is really smart. If the day is the first of the month and you subtract 1 you are providing 0 as the day. It will convert to last day of previous month. Same if you provided a day like 32.
 

gojets1721

Registered User.
Local time
Today, 02:21
Joined
Jun 11, 2019
Messages
430
FYI. The date serial is really smart. If the day is the first of the month and you subtract 1 you are providing 0 as the day. It will convert to last day of previous month. Same if you provided a day like 32.
Perfect. Thank you!!
 

Minty

AWF VIP
Local time
Today, 10:21
Joined
Jul 26, 2013
Messages
10,371
Well, I would possibly subtract 1 from the year rather than the day section of the function?

Try it and see what happens. It won't bite you.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:21
Joined
May 21, 2018
Messages
8,554
Sorry typed on a phone. Subtract one from year, year(date) -1 and add a day not subtract.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:21
Joined
May 21, 2018
Messages
8,554
Point is you want it to be a day before in the previous year. Not always 365.
Unless you do want 365 regardless of leap year. Need to be specific which way.
 

Users who are viewing this thread

Top Bottom