elena1234

Date Format in Python

Apr 20th, 2022 (edited)
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import pandas as pd
  2.  
  3.  
  4. date = '10-Dec-2022'
  5. date_format = pd.to_datetime(date, format = '%d-%b-%Y')
  6. print(date_format.year)
  7. print(date_format.day_name())
  8.  
  9. '''
  10. %Y  Full year with century  2021,2022
  11. %y  Year without century with zero padded value 00,01,….21,22…,99
  12. %-y Year without century    0,1…,99
  13. %m  Month with zero padded value    01-12
  14. %-m Month without zero padded value 1-12
  15. %B  Full month name January, February,…, December
  16. %b  Short form of month     Jan, Feb,…,Dec
  17. %A  Full weekday name   Sunday, Monday,..
  18. %a  Short form of weekday name  Sun, Mon,..
  19. %w  Weekday as decimal value    0-6
  20. %d  Days with zero padded value 01-31
  21. %-d Days with decimal value 1-31
  22. %H  Hour (24-hour clock) as a zero-padded value.    00-23
  23. %-H Hour (24-hour clock) without zero-padded value. 0,1,…,23
  24. %I  Hour (12-hour clock) as a zero-padded value.    01-12
  25. %-I Hour (12-hour clock) without zero-padded value. 1-12
  26. %M  Mins with zero-padded   00-59
  27. %-M Mins without zero padded value  0-59
  28. %S  Secs with zero padded value 00-59
  29. %-S Secs without zero padded value  0-59
  30. %f  Micro Secs with zero-padded value   000000 – 999999
  31. %p  Locale’s AM or PM.    AM/PM
  32. %j  Day of the year with zero padded value  001-366
  33. %-j Day of the year without zero padded value   1-366
  34. %z  UTC offset in the form +HHMM or -HHMM.   
  35. %Z  Time zone name.  
  36. %C  Locale’s appropriate date and time    Fri Apr 02 02:09:07 2020
  37. %x  Locale’s appropriate date 02/04/22
  38. %X  Locale’s appropriate time 02:04:22
  39. %W  Week number of the year. Monday as first day of week    00-53
  40. %U  Week number of the year. Sunday as first day of week    00-53 '''
  41.  
Add Comment
Please, Sign In to add comment