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

  • SEARCH
  • Home
  • 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 8173699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:15:06+00:00 2026-06-06T22:15:06+00:00

Using import datetime in python, is it possible to take a formatted time/date string

  • 0

Using import datetime in python, is it possible to take a formatted time/date string such as:

2012-06-21 20:36:11

And convert it into an object that I can then use to produce a newly formatted string such as:

21st June 2012 20:36
  • 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-06-06T22:15:09+00:00Added an answer on June 6, 2026 at 10:15 pm
    import time
    
    s = '2012-06-21 20:36:11'
    
    t = time.strptime(s, '%Y-%m-%d %H:%M:%S')
    print time.strftime('%d %B %Y %H:%M', t)
    

    returns

    21 June 2012 20:36
    

    If you really want the ‘st’,

    def nth(n):
        return str(n) + nth.ext[int(n)%10]
    nth.ext = ['th', 'st', 'nd', 'rd'] + ['th']*6
    
    print nth(t.tm_mday) + time.strftime(' %B %Y %H:%M', t)
    

    gets you

    21st June 2012 20:36
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following to get utc datetime: import datetime import time from pytz
I would like to convert datetime.ctime() values to Unicode. Using Python 2.6.4 running under
I am using python logger. The following is my code: import os import time
Using python I have to retrieve value of time and date of an event
I'm trying to convert a parameter of type string to a date time. I'm
I'm doing a table import using a multiple INSERT (INSERT INTO ... VALUES (1),
I have the following script for sending mails using python import smtplib from email.mime.multipart
Possible Duplicate: comparing contents of two files using python I have a file name
I'm try to insert values into my sqlite table using a python script. It
I'm using pyodbc to query to an SQL Server database import datetime import pyodbc

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.