473,466 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert Date to Short formate

Hello,
there is string value 'Dec 06, 2000' I want to convert that string
date to SHORT FORMAT like '2000-12-06-. Please help me how do I do
that? I'm new in Jython.
Thanks,
aqmaiya

Jun 7 '06 #1
2 5713
aqmaiya wrote:
there is string value 'Dec 06, 2000' I want to convert that string
date to SHORT FORMAT like '2000-12-06-. Please help me how do I do
that?


you mean ISO format, right?

the easiest way is probably to use the time.strptime module to parse the
original string into a time tuple, and then use time.strftime to format
the tuple as an ISO date:
s = "Dec 06, 2000"
t = time.strptime(s, "%b %d, %Y")
t (2000, 12, 6, 0, 0, 0, 2, 341, -1) time.strftime("%Y-%m-%d", t)

'2000-12-06'

also see:

http://docs.python.org/lib/module-time.html

</F>

Jun 7 '06 #2
On 8/06/2006 5:50 AM, aqmaiya wrote:
Hello,
there is string value 'Dec 06, 2000' I want to convert that string
date to SHORT FORMAT like '2000-12-06-. Please help me how do I do
that? I'm new in Jython.
Thanks,
aqmaiya


Two ways (at least):

(1) check out the strptime and strftime (p == parse, f == format)
functions in the time module

In general, the datetime module is much to be preferred for working with
dates and times -- unless of course you need to mimic functions from the
C time.h library -- however the datetime module won't be getting a
strptime until version 2.5, which is still in alpha test.

(2) As you are new to Python, you might like to try your skills with
basic parts from the Python toolkit, like dictionaries and slicing, and
write a function yourself, specialised to that particular format. Here
are some hints:

# example Dec 06, 2000
# ruler 0123456789012

mpart = data[0:3]
# similarly: dpart, ypart

month_dict = {'jan': 1, ....., 'dec': 12}
month_num = month_dict[mpart.lower()] # will work with Dec, dec, DEC

result = '%s-%02d-%s' % (ypart, month_num, dpart)

How much validation you do is up to you :-)

HTH,
John
Jun 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Omer kamal | last post by:
Dear all, I want to save my data into MS Access database Table which consist of some fields with short date and short time formats. I try to save data in to the said table and I am getting error...
3
by: Henry Lee | last post by:
hi , all In ASP2.0 , the date object always showing like "3/27/2006 12:00:00 AM" How to remove "12:00:00 AM" and only make it shows "3/27/2006" ? Thanks very much Henry
11
kamill
by: kamill | last post by:
I have a timestamp type field into my mysql database table. Now threw php i need to change it into mm:dd:yy formate.Threw witch function i can do it. Please help me with an examole. suppose...
3
by: raahat | last post by:
hi, i need to do desperately the way of storing american DATE formate( like 27-02-2007) in mysql table.i searched on the web a lot,but didnt find anything.PLZ i need someone's help.
2
by: sourabhmca | last post by:
hi friend , I took joindate field in table as smalldatetime type now I want to convert it in String type and formate is dd/mm/yyyy .how to convert it . and again i want to change this String type...
1
by: Gurunath | last post by:
Hello All, In database i am storing value in "2007-03-22 02:00:00-05" formate And from input i am taking start date in "2007-3-25" formate and end date in "2007-5-20" formate . Now what i...
2
by: remya1000 | last post by:
How to convert UTC formate time to local time.using vb.net. In my application in some point of the execution i need to retrieve a date,but instead of date i get some numbers,for example...
6
by: Steve Ryan | last post by:
can anyone send me to some good examples of edit in place for data frid columns i see dot net let me assign a control in the IDE any good sources of reading on editing columns with controls...
1
by: rajeevsoniya | last post by:
i am having date formate like this 23:15:45 Jan 17, 2008 i want to change it to 23:15:45 29:01:2008 how can i do this using php
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
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,...
1
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...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.