Legacy – Formatting Date Workout
- 01:55
Workout demonstrating how to format the dates in Python
Downloads
Formatting Date - Python Workout FilesGlossary
Date Library Formatting DateTranscript
So how do we format date and time in Python? In case we want the shorter format of a month or the shorter format of a date or the even the local data type? How do we do it? So when formatting the date, we need to remember a few key things before doing that. Firstly, we need to import the date time from date time import data and because we're dealing with types here, so now for date format. The key things to remember firstly, imagine that we have now is the data type . now, so it's the current day and time. Perfect, so if you want to print now and see what console does, perfect, that's the current date and time. So print now dot str f time, it's just formatting the time say you want the current year how do you do it? You have say percentage capital Y in quotations, and you run this you get year 2019. If you say percentage, smaller wise molecules why it gives you just last two numbers 19. Similarly, for the month, if you say percentage, capital P gives you the December and percentage small b, it gives Dec. Similarly, for the day of the month, it's just d and it gives you 18th. Now for weekdays, percentage capital a would give you Wednesday, percentage, a gives you WD shorter version of Wednesday. So simple the strf time the structure format in time lets you format the actual date. Rather than having the whole thing you can have just a short version