473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

converting date

Hi Guys

I have a date in string format that i need to convert into date format

Eg: Fri, 29 Jul 2011 08:15:34 -0400

i need to convert it to a normal date and time format eg: 2011-07-29 08:15:34 -0400

i am new to python can you please assist me
Aug 3 '11 #1
1 1552
bvdet
2,851 Expert Mod 2GB
It can be done like this:
Expand|Select|Wrap|Line Numbers
  1. >>> s = 'Fri, 29 Jul 2011 08:15:34 -0400'
  2. >>> s.split()
  3. ['Fri,', '29', 'Jul', '2011', '08:15:34', '-0400']
  4. >>> import time
  5. >>> t = time.strptime(' '.join(s.split()[:4]), '%a, %d %b %Y')
  6. >>> s1 = time.strftime("%Y-%m-%d ", t)+ " ".join(s.split()[4:])
  7. >>> s1
  8. '2011-07-29 08:15:34 -0400'
  9. >>> 
Aug 3 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gary Smith | last post by:
I my SQL Datareader I am loading the date data into text box. Here is my code txtActOpenDate.Text = MyDataReader("ActOpenDt").ToString() txtActOpenDate.Text is displaying the date and...
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
4
by: krupalreddy | last post by:
i have a problem with date i have two dates. one is in Date type and the other one is in String type. i need to compare these two dates. for this i try to convert date which is in String type to...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
2
by: jacc14 | last post by:
Hi Hope there is someone out there that can help. I am sure this is an easy one although not easy to explain. I have a form which produces a report using a query. On the form I have a start and...
4
by: gubbachchi | last post by:
Hi, I have an issue regarding the php date format. I choose the date from date-picker which is in the format date('Y-m-d') i.e. 2008-09-12, then I will store this date in the variable $date_id and...
4
by: nikos | last post by:
Hi, I have a table with one of the columns configured to record dates as ('#', 'MM/DD/YYYY'). However, two entries in that column are of format YYYY and MM/YYYY. How can I change only those two...
1
by: =?Utf-8?B?bGF3ODc4Nw==?= | last post by:
i am looking for some MS Excel formula or MS Visal Basic Marco for converting Date to Lunar Date. tks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.