473,569 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Convert String To Date?

2 New Member
Dear Freinds
I have string contains the date like "21Jun2000"
What I want to do is to convert that string into date in the following format
21 Jun 2000

Plesae help me as soon as possible
'Thank you very much
Feb 17 '07 #1
4 83866
bartonc
6,596 Recognized Expert Expert
Dear Freinds
I have string contains the date like "21Jun2000"
What I want to do is to convert that string into date in the following format
21 Jun 2000

Plesae help me as soon as possible
'Thank you very much
If the format is constant you could

>>> date = "21Jun2000"
>>> day = date[:2]
>>> month = date[2:5]
>>> year = date[5:]
>>> print day, month, year
21 Jun 2000
Feb 17 '07 #2
ghostdog74
511 Recognized Expert Contributor
the usual way to do it for any date format string is using time.strptime and time.strftime.j ust an example
Expand|Select|Wrap|Line Numbers
  1. Type "help", "copyright", "credits" or "license" for more information.
  2. >>> import time
  3. >>> datestring = "21Jun2000"
  4. >>> c = time.strptime(datestring,"%d%b%Y")
  5. >>> time.strftime("%d %b %Y",c)
  6. '21 Jun 2000'
  7. >>> 
  8.  
Feb 17 '07 #3
bartonc
6,596 Recognized Expert Expert
the usual way to do it for any date format string is using time.strptime and time.strftime.j ust an example
Expand|Select|Wrap|Line Numbers
  1. Type "help", "copyright", "credits" or "license" for more information.
  2. >>> import time
  3. >>> datestring = "21Jun2000"
  4. >>> c = time.strptime(datestring,"%d%b%Y")
  5. >>> time.strftime("%d %b %Y",c)
  6. '21 Jun 2000'
  7. >>> 
  8.  
Hey! That's awesome. I always thought that you needed a date.date object for that to work.
Feb 17 '07 #4
Aobaidat79
2 New Member
the usual way to do it for any date format string is using time.strptime and time.strftime.j ust an example
Expand|Select|Wrap|Line Numbers
  1. Type "help", "copyright", "credits" or "license" for more information.
  2. >>> import time
  3. >>> datestring = "21Jun2000"
  4. >>> c = time.strptime(datestring,"%d%b%Y")
  5. >>> time.strftime("%d %b %Y",c)
  6. '21 Jun 2000'
  7. >>> 
  8.  
You are a smart person
Thank you all
Feb 19 '07 #5

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

Similar topics

4
5358
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm...
2
10869
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
3093
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" "ddMMyyyy" June 1, 2005 "09-07-05" "MM-dd-yy" Sept 7, 2005 Is there any functions to convert?
1
4530
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 = Math.Floor(JD+0.5); double W = Math.Floor((Z - 1867216.25)/36524.25); double X = Math.Floor(W/4);
5
12700
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
2
20996
by: Kakishev | last post by:
I have a problem at how best to convert a Date into a text field and keep the format dd/mmm/yyyy (01-FEB-2007). The problem is that dates are imported from SQL into an access front end Database. When the dates are imported they are in the format dd/mm/yyyy. However on the reports the dates are in the in the format dd/mmm/yyyy. I now need...
19
20223
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the easiest method to add the current date/time (dd/mm/yy hh:mm:ss) via JDBC in DATE format i.e. convert STRING to DATE or format the DATE without...
5
3417
satiss7pwr
by: satiss7pwr | last post by:
I have a string date like this: "3/28/2008 12:05:45 pm" i want to convert it into date and display the out put any one can help me plssssssssss
3
2886
by: tanishka singh | last post by:
How do you convert string from database into date in asp.net? Dim output = (From tlb In obj.SelectRecordAll_SalesInquiryRegister _ Join tlb1 In LatestPOs On tlb.SIR_OfferNo Equals tlb1.OfferNo _ And tlb.SIR_AlterationNo Equals tlb1.PORevNo _ Order By tlb.SIR_Flag _ ...
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.