Skip to content
Related Articles

Related Articles

Python Tweepy – Getting the date and time when a tweet was tweeted

View Discussion
Improve Article
Save Article
  • Last Updated : 18 Jun, 2020
View Discussion
Improve Article
Save Article

In this article we will see how we can get the date and time when a status/tweet was posted/tweeted. The created_at attribute of the Status object provides us with a datetime object which tell us when the status was posted.

Identifying the date when a status was posted in the GUI :

In the above mentioned status, the status was posted on : Jun 11

In order to get the date and time when the status was posted, we have to do the following :

  1. Identify the status ID of the status from the GUI.
  2. Get the Status object of the status using the get_status() method with the status ID.
  3. From this object, fetch the created_at attribute present in it.

Example 1 : Consider the following status :

We will use the status ID to fetch the status. The status ID of the above mentioned status is 1272771459249844224.




# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# the ID of the status
id = 1272771459249844224
  
# fetching the status
user = api.get_status(id)
  
# fetching the created_at attribute
created_at = status.created_at 
  
print("The status was created at : " + str(created_at))

Output :

The status was created at : 2020-06-16 06:02:17

Example 2 : Consider the following status :

We will use the status ID to fetch the status. The status ID of the above mentioned status is 1272479136133627905.




# the ID of the status
id = 1272479136133627905
  
# fetching the status
user = api.get_status(id)
  
# fetching the created_at attribute
created_at = status.created_at 
  
print("The status was created at : " + str(created_at))

Output :

The status was created at : 2020-06-15 10:40:42

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!