473,326 Members | 2,175 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,326 software developers and data experts.

How to convert string to date object?

i have date in string in this format
eg. 1/20/21011 i need to convert it into the date object
Jan 25 '11 #1

✓ answered by bvdet

Expand|Select|Wrap|Line Numbers
  1. >>> import time
  2. >>> s = "1/20/2011"
  3. >>> time.strptime(s, "%m/%d/%Y")
  4. (2011, 1, 20, 0, 0, 0, 3, 20, -1)
  5. >>> 

4 3636
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. >>> import time
  2. >>> s = "1/20/2011"
  3. >>> time.strptime(s, "%m/%d/%Y")
  4. (2011, 1, 20, 0, 0, 0, 3, 20, -1)
  5. >>> 
Jan 25 '11 #2
thanks i tried it and it works fine i alos tried same for time also but i get problem when the time is provide in this format
10:30:00 AM
Jan 26 '11 #3
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. >>> import time
  2. >>> s = "1/20/2011 10:30:00 AM"
  3. >>> time.strptime(s, "%m/%d/%Y %I:%M:%S %p")
  4. (2011, 1, 20, 10, 30, 0, 3, 20, -1)
  5. >>> time.strptime("1/20/2011 10:30:00 PM", "%m/%d/%Y %I:%M:%S %p")
  6. (2011, 1, 20, 22, 30, 0, 3, 20, -1)
  7. >>> 
Jan 26 '11 #4
Thanks very much
Jan 26 '11 #5

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

Similar topics

5
by: JimMenees | last post by:
I know there's an easy answer to this which is escaping me: -------------------------------------------------------------------------- ----------------------- I have clickable thumb images which...
7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
2
by: Abhishek Srivastava | last post by:
Hello All, I wrote the following program. using System; using System.Globalization; public class ShortDateTest { public static void Main(string args)
1
by: ABC | last post by:
How to convert a date string to datetime value with custom date format? e.g. Date String Date Format Result (DateTime value) "05/07/2004" "MM/dd/yyyy" May 7, 2004 "01062005" ...
1
by: Sam | last post by:
How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on following guideline found at Internet? To convert Julian date to Gregorian date: double JD = 2299160.5; double Z =...
1
by: xendrax | last post by:
I was told on this site eval was bad but its the only way i can work out how to do it.. their example was use var imdesc = document.myform.value not var imdesc = eval("document.myform." +...
5
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
6
by: Gretsch | last post by:
Hi, I have some XML data which contains a date in dd/mm/yyyy format (ie UK date format). In javascript I need to read this date then calculate the age (in days& decimals) of the XML data. I...
7
devonknows
by: devonknows | last post by:
Hi, The problem im having is, Im creating a user control. The user (via the Property Page's) will set his own menu titles, and the choose a form of which that title links to. If that makes sense. ...
4
by: Tony B | last post by:
I'm looking to convert a string in "dd/MM/yy" format into a date object. How do I go about this ?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.