Search code examples
pythonredditpraw

Get time since comment was posted [Praw]


Is there a way to get the time since a comment was posted using Praw?

I've looked over the docs but couldn't find any mention of it, if there isn't, are there any workarounds to get the time?


Solution

  • I don't know, if you're still looking for an answer. In any case, someone might find this via search engine, so here's an idea:

    import praw
    import datetime
    
    reddit = praw.Reddit(...)
    comment = reddit.comment(id="ctu29cb")
    
    now = int(datetime.datetime.timestamp(datetime.datetime.today()))
    then = int(comment.created)
    delta = now - then
    
    print("comment has been created with timestamp", then)
    print("which means on", datetime.datetime.fromtimestamp(then).strftime('%Y-%m-%d %H:%M:%S'))
    print("that was", delta, "seconds or", str(datetime.timedelta(seconds=delta)), "hours ago")
    

    which returns

    comment has been created with timestamp 1438924830
    which means on 2015-08-07 05:20:30
    that was 69533363 seconds or 804 days, 18:49:23 hours ago