반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- numpy
- Excel
- PostgreSQL
- PANDAS
- matplotlib
- google apps script
- Redshift
- dataframe
- math
- PySpark
- list
- Apache
- c#
- Presto
- gas
- 파이썬
- django
- Kotlin
- Tkinter
- Google Spreadsheet
- Java
- Github
- string
- Python
- array
- hive
- SQL
- Google Excel
- GIT
Archives
- Today
- Total
달나라 노트
Python datetime : year, month, day (년, 월, 일 추출하기) 본문
Python/Python datetime
Python datetime : year, month, day (년, 월, 일 추출하기)
CosmosProject 2020. 12. 23. 02:39728x90
반응형
import datetime
today = datetime.date.today()
y = today.year
m = today.month
d = today.day
w = today.weekday()
print(y)
print(m)
print(d)
print(w)
- Result
2020
3
8
6
datetime 모듈의 date class에 today method를 사용하거나 직접 년, 월, 일을 입력해주어 date 객체를 생성합니다.
이 생성한 date class의 year, month, day attribute를 이용하여 년, 월, 일을 추출할 수 있으며 weekday method를 이용하여 요일별 숫자(월 = 0, 화 = 1, ... 일 = 6)를 얻어낼 수 있습니다.
728x90
반응형
'Python > Python datetime' 카테고리의 다른 글
| Python datetime : now(현재 날짜와 시간) & today(현재 날짜) (0) | 2020.12.23 |
|---|---|
| Python datetime : datetime class(날짜 + 시간 객체) (0) | 2020.12.23 |
| Python datetime : time class(시간 객체) & hour, minute, second, microsecond(시간, 분, 초, 마이크로초 attribute) (0) | 2020.12.23 |
| Python datetime : fromtimestamp (Unix timestamp를 날짜로 변환하기) (0) | 2020.12.23 |
| Python datetime : date (숫자들을 조합하여 날짜 만들기) (0) | 2020.12.23 |
Comments