Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Datetime/Datetime_Convert_datetime_object_to_string_date.ipynb
2973 views
Kernel: Python 3

Datetime.png

Datetime - Convert datetime object to a formatted date string

Give Feedback | Bug report

Tags: #datetime #snippet #operations #python

Last update: 2023-07-05 (Created: 2023-07-05)

Description: This notebook provides an introduction to using the Python datetime library to work with dates and times.

Input

Import libraries

from datetime import datetime

Setup Variables

To parse your date format : you can use the d3 time format documentation

  • datetime_obj: Datetime object

  • string_date_format: String date format

# Datetime object datetime_obj = datetime(2020, 8, 1) # New date format you want to use string_date_format = "%Y-W%U"

Model

Convert a datetime object to string date

new_date = datetime_obj.strftime(string_date_format) new_date

Output

Display new date

new_date