Template request | Bug report | Generate Data Product
Tags: #python #datetime #snippet #operations
Author: Florent Ravenel
Description: This notebook provides an introduction to using the Python datetime library to work with dates and times.
from datetime import datetime
- To parse your date format : you can use the d3 time format documentation
# Date string format
date_string = "2022-02-25"
# Your date string format
current_format = "%Y-%m-%d"
# New date format you want to use
new_format = "%Y-W%U"
date_datetime = datetime.strptime(date_string, current_format)
date_datetime
new_date = date_datetime.strftime(new_format)
new_date
new_date = datetime.strptime(date_string, current_format).strftime(new_format)
new_date
new_date