- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34484 Articles for Programming
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
13K+ Views
You can use the fromtimestamp function from the datetime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the datetime object corresponding to the timestamp.Exampleimport datetime timestamp = datetime.datetime.fromtimestamp(1500000000) print(timestamp.strftime('%Y-%m-%d %H:%M:%S'))OutputThis will give the output −2017-07-14 08:10:00
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
12K+ Views
In Python, you can convert a string to date object using the strptime() function. Provide the date string and the format in which the date is specified. Example import datetime date_str = '29/12/2017' # The date - 29 Dec 2017 format_str = '%d/%m/%Y' # The format datetime_obj = datetime.datetime.strptime(date_str, format_str) print(datetime_obj.date())OutputThis will give the output −2017-12-29
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
694 Views
You can get the Python date object for last wednesday using some Python date math. Whatever the day of the week it is today, subtracting 2 from it and taking the modulus of the result by 7 will give us how back was wedenesday. examplefrom datetime import date from datetime import timedelta today = date.today() offset = (today.weekday() - 2) % 7 last_wednesday = today - timedelta(days=offset)OutputThis will give you the output −2017-12-27
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
2K+ Views
There is no standard JSON format for dates. Although JavaScript does have a standard date format that is human readable, sorts correctly, includes fractional seconds(which can help re-establish chronology) and conforms to ISO 8601. You can convert a Python date to the JS date format using the strftime function and deserialize it using the client that needs this date. To get an ISO 8601 date in string format in Python 3, you can simply use the isoformat function. It returns the date in the ISO 8601 format. For example, if you give it the date 31/12/2017, it'll give you the ... Read More
![Vikram Chiluka](https://www.tutorialspoint.com/assets/profiles/495654/profile/60_4081994-1659334126.jpg)
34K+ Views
In this article, we will show you how to sort a Python date string list. Now we see 3 methods to accomplish this task− Now we see 2 methods to accomplish this task− Using sort() and lambda functions Using sort() function Using sorted function Method 1: Using sort() and lambda functions Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Use the import keyword, to import the datetime from datetime module (To work with dates and times, Python has a module called datetime). Create a variable to store the input list ... Read More
![Pranav Indukuri](https://www.tutorialspoint.com/assets/profiles/512605/profile/60_2168928-1662357840.jpeg)
28K+ Views
A UNIX timestamp is the total number of seconds that have been counted since the epoch. An epoch is the starting point of time and is platform-dependent. The epoch is January 1, 1970, 00:00:00 (UTC) on Windows and most Unix systems, and leap seconds are not included in the time in seconds since the epoch. In this article, we going to see how to convert a python date to a UNIX timestamp. Datetime to UNIX timestamp Here we convert a python date to a UNIX timestamp by using the time.mktime() method. In this example, we initially imported the datetime module. ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
1K+ Views
If you print the dates directly using a print function, you'd get regular dates, Exampleimport datetime today = datetime.date.today() print(today)OutputYou will get the output −2018-1-2which is exactly what you want. But when you append this to a list and then try to print it, Exampleimport datetime my_list = [] today = datetime.date.today() my_list.append(today) print(my_list)OutputYou will get the output −[datetime.date(2018, 1, 2)]This is happening because datetimes are objects. Therefore, when you manipulate them, you manipulate objects, not strings, not timestamps nor anything. Any object in Python have TWO string representations. The regular representation that is used by "print", can be get ... Read More
![Vikram Chiluka](https://www.tutorialspoint.com/assets/profiles/495654/profile/60_4081994-1659334126.jpg)
3K+ Views
In this article, we will show you how to set the first day of each week to a weekday using Python. Now we see 2 methods to accomplish this task− Using setfirstweekday() function Using setfirstweekday() function to set a given weekday Number Method 1: Using setfirstweekday() function to set given weekDay Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Use the import keyword, to import the calendar module. Use the prmonth() function (It is used to print the calendar for a month) of the calendar module to print the calendar ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
230 Views
You can use the calendar module to find the weekday of first day of the month and number of days in month. Using this information you can easily get the Last day of the month. The calender module has a method, monthrange(year, month) that returns the weekday of first day of the month and number of days in month, for the specified year and month.Exampleimport calendar day, num_days = calendar.monthrange(2017, 12) last_week = num_days % 7 last_day = (day + last_week) % 7 print(last_day)OutputThis will give the output −0Note that days are from 0-6 starting with sunday.
![Pranav Indukuri](https://www.tutorialspoint.com/assets/profiles/512605/profile/60_2168928-1662357840.jpeg)
32K+ Views
In this article we will discuss how to find the number of days between two dates using Python. We use the datetime module to calculate the number of days between two dates using python. datetime module Python has a built-in datetime module that assists us in resolving a number of date-related issues. We just input the two dates with the date type and subtract them to discover the difference between the two dates, which gives us the number of days between the two dates. Syntax The syntax of the date() method in datetime module is as follows. datetime.date(year, month, day) ... Read More