473,385 Members | 1,606 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,385 software developers and data experts.

Time formatting and date suffixes

This seems like a dead simple question, as it's so rudimentary I
can't believe it hasn't been addressed before. I'm using the
time.strftime() function (actually the mxDateTime implementation, but
they're compatible so it shouldn't matter) to spit out fairly basic
date formats, to wit:

January 25th, 2005

The various and sundry date objects in both mxDateTime and Python
proper's time/datetime don't seem to have anything anywhere dealing
with the 'th' suffix on the date. So in other words, I can use
strftime() to get 'January 25, 2005' but don't see anything dealing
with outputting the suffixes like 'th', 'nd' and the like. Googling
around and searching this list's archives aren't turning anything up,
either.

Am I missing something obvious, or is it just really, really frowned
upon to use such a locale-specific function as English date suffixes?

Thanks,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission. If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

Jul 25 '05 #1
2 3335
Jeffrey E. Forcier wrote:
This seems like a dead simple question, as it's so rudimentary I can't
believe it hasn't been addressed before. I'm using the time.strftime()
function (actually the mxDateTime implementation, but they're
compatible so it shouldn't matter) to spit out fairly basic date
formats, to wit:

January 25th, 2005

The various and sundry date objects in both mxDateTime and Python
proper's time/datetime don't seem to have anything anywhere dealing
with the 'th' suffix on the date. So in other words, I can use
strftime() to get 'January 25, 2005' but don't see anything dealing
with outputting the suffixes like 'th', 'nd' and the like. Googling
around and searching this list's archives aren't turning anything up,
either.

Am I missing something obvious, or is it just really, really frowned
upon to use such a locale-specific function as English date suffixes?


I think the lack of facility is probably due to there being not much
call for that sort of thing -- people doesn't usually go for the "third
day after Michaelmas in the year of our Lord two thousand and five, at
ten o'clock in the forenoon" style these days. If you don't use text,
but stick with the recognisable unambiguous ISO standard format
(2005-01-25), you don't have to worry about locales. However I guess you
have to keep the PHB happy; you can write your own routine in a few lines.

Hint:

if 4 <= day <= 20 or 24 <= day <= 30:
suffix = "th"
else:
suffix = ["st", "nd", "rd"][day % 10 - 1]

HTH,
John
Jul 26 '05 #2
See, I was thinking I'd have to write a short function to do it myself,
but I hadn't realized it could be quite *that* short. Thanks! That'll
do quite nicely, and is definitely something I'm going to throw in my
"general utility functions" folder :)

Regards,
Jeff

Jul 26 '05 #3

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
2
by: psycho | last post by:
in sqlserver in date is stored in a particular format. Date and time are stored in same column. so if i want to display only date or only time in the datagrid is there any solution?
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
1
by: jonny | last post by:
Option Explicit Private mdTarget1 As Date Private mdTarget2 As Date ' called on form load Public Sub SetRecordStartTime() mdTarget1 = DateAdd("n", 60, Time) mdTarget2 = DateAdd("n", 120,...
7
by: christery | last post by:
Anyone got a clue to why ther is a T between date and time in the "formatted for sorting" or whatewer they call it, and a Z at the end after seconds- got it fixed for my cobol programmer by...
1
by: Cartoper | last post by:
How does one go about formatting the date/time string correctly to set the If-Modified-Since to the current date/time in an AJAX call? I know I need something like this: ...
14
by: Arjen | last post by:
Hi, I have a string with this value 07/11/2008. As you see no time included. How can I parse this string to a datetime variable? I tried to do this but I get the exception that the format is...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.