Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1015365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:23:27+00:00 2026-05-16T10:23:27+00:00

I want to convert a Python datetime to an RFC 2822 datetime. I’ve tried

  • 0

I want to convert a Python datetime to an RFC 2822 datetime. I’ve tried these methods to no avail:

>>> from email.Utils import formatdate
>>> import datetime
>>> formatdate(datetime.datetime.now())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/email    /utils.py", line 159, in formatdate
    now = time.gmtime(timeval)
TypeError: a float is required
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:23:28+00:00Added an answer on May 16, 2026 at 10:23 am

    Here’s some working code, broken down into simple pieces just for clarity:

    >>> import datetime
    >>> import time
    >>> from email import utils
    >>> nowdt = datetime.datetime.now()
    >>> nowtuple = nowdt.timetuple()
    >>> nowtimestamp = time.mktime(nowtuple)
    >>> utils.formatdate(nowtimestamp)
    'Tue, 10 Aug 2010 20:43:53 -0000'
    

    Explanation: email.utils.formatdate wants a timestamp — i.e., a float with seconds (and fraction thereof) since the epoch. A datetime instance doesn’t give you a timestamp directly — but, it can give you a time-tuple with the timetuple method, and time.mktime of course can then make a timestamp from such a tuple.

    EDIT: In Python 3.3 and newer you can do the same in less steps:

    >>> import datetime
    >>> from email import utils
    >>> nowdt = datetime.datetime.now()
    >>> utils.format_datetime(nowdt)
    'Tue, 10 Feb 2020 10:06:53 -0000'
    

    See format_datetime docs for details on usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm guessing you don't actually want all those 'static's in… May 16, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer My first impulse would be to use an image or… May 16, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer To get information about an open fd, you can use… May 16, 2026 at 4:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

So I have datetime objects in UTC time and I want to convert them
I want to pass a datetime value into my python script on the command
I want to convert Python string to URL syntax. For example >>> u'한글'.encode('utf-8') '\xed\x95\x9c\xea\xb8\x80'
I just installed Jython 2.5.1. I want to convert my Python file into Java
I had written a program in Python 3, but now want to convert it
I want to convert -123.456 into a C double for network transmission in python.
I want to convert an ip address read from a file in the decimal
How do I convert a string to a date object in python? The string
I want to convert the mysql database table contents to an Excel(.xls) or comma
I want to convert the input 24 bit PNG image to 8 bit, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.