DEV Community

Cover image for A happy new year to everyone in Python!
Everton Tenorio
Everton Tenorio

Posted on

A happy new year to everyone in Python!

Hello devs, may we continue to grow in our tasks and studies throughout 2025. This year, I've learned a lot here on dev.to, so, following the community's premise, Iā€™m sharing a Python code snippet for those already counting down the hours to the new year.

from datetime import datetime, timedelta

today = datetime.now()
date_format = "%m/%d/%Y"

if today.strftime(date_format) == "12/31/2024":
    print(today.strftime("%H:%M:%S"))
else:
    new_year = today + timedelta(days=1)
    print(f"It's {new_year.strftime('%m/%d/%Y')}. HAPPY NEW YEAR!")
Enter fullscreen mode Exit fullscreen mode

The datetime module is part of Python's standard library and provides classes for manipulating dates and times, such as the datetime class. The timedelta class represents a time difference (duration), like "2 days," "5 hours," or "30 minutes." It is used for operations like adding or subtracting durations from a date/time object. The code checks whether we are on the last day of 2024, and if not...

It's 01/01/2025. HAPPY NEW YEAR! šŸŽ‡ šŸ„‚šŸ¾

šŸ‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free ā†’

šŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay