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! šŸŽ‡ šŸ„‚šŸ¾

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Docusign

šŸ› ļø Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

šŸ‘‹ Kindness is contagious

Please leave a ā¤ļø or a friendly comment on this post if you found it helpful!

Okay