473,406 Members | 2,378 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.

Returning Date As String ?

I am wanting to return the system date using the following:

date.today()

How would I then convert this to a string ?

Pete

Jul 19 '05 #1
3 29417
if you're using date.today():
x=date.today()

Jul 19 '05 #2
Peter Moscatt <pg*******@optushome.com.au> wrote:
I am wanting to return the system date using the following:

date.today()

How would I then convert this to a string ?

Pete


datetime.data objects have a __str__() method. To convert one to a string,
you just have to cause its __str__() to be invoked. The most common ways
of doing that are str(), %s, or print:
import datetime
d = datetime.date.today()
d datetime.date(2005, 5, 14) # this is the repr() of the object print d 2005-05-14 str(d) '2005-05-14' '%s' % d

'2005-05-14'
Jul 19 '05 #3
Peter Moscatt wrote:
I am wanting to return the system date using the following:

date.today()

How would I then convert this to a string ?


Use the strftime method. The formatting directives are documented here:
http://docs.python.org/lib/module-time.html

Example: date.today().strftime("%B %d, %Y")

--
Brian Beck
Adventurer of the First Order
Jul 19 '05 #4

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

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
10
by: Kim Hellan | last post by:
I have a simple string in the format "DD-MM-YY hh:mm:ss", that I need to convert to a DateTime value. I know this is a standard problem, but please don't just link to all the MSDN pages regarding...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
0
by: Fritz | last post by:
I developed a program on windows 98 it also works on windows xp however when I run it on xp I don't get the right characters returned on the date string. Is the date string different in xp? I realize...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
9
by: fpvt2 | last post by:
In VB6, I can format a date string like the following: format("12/15/06","yymmdd") and it returns 061215. In VB.Net, when I do the following: sdate.tostring("yymmdd"), it gave me an error "Value...
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
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: adh | last post by:
In c# you can return a String() but in VB.NET2005 it does not work (the webservice test sends to the error page). See MS AJAX Controls Toolkit.Autocomplete which demands a String() reply. I...
2
by: GaryDean | last post by:
The following command... string DebugString = System.Web.HttpContext.Current.Server.MapPath("App_Themes"); is executed from my ThemeManager.cs class in my App_code directory It returns......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
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
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...

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.