Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BikashKatwal's avatar

Add 1 year in today's date default in database

How can I add 1 year in today's date default in the database? I am trying to add by doing the following but I feel this is now the correct way because if I just add the year then next year that date would not be present in the calendar. For Eg: 29-Feb-2020 would not be in 2021. So what would be the correct way to add a year ahead date in the database by default.

I just did but this is not the correct way as per my thought

\Carbon\Carbon::now()->addYear()
0 likes
3 replies
kmjadeja's avatar
kmjadeja
Best Answer
Level 15

Hey @bikashkatwal,

  • Carbon will add days if you add Year, so basically it'll calculate the day and add that days to the given date and return the next year's date.

So you are safe for this kind of situation, Carbon will manage all the details for you. It'll work perfectly fine for leap years. ;)

Tray2's avatar

Your solution is what I would go with

\Carbon\Carbon::now()->addYear()

I would import the carbon namespace though.

fylzero's avatar

@bikashkatwal @tray2

You can also just reference now() as a helper method like so, no need to import anything, cleaner, easier to remember and read.

now()->addYear()

Please or to participate in this conversation.