473,587 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 29426
if you're using date.today():
x=date.today()

Jul 19 '05 #2
Peter Moscatt <pg*******@optu shome.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.t oday()
d datetime.date(2 005, 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().st rftime("%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
3725
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 function 1) parsedate function failed if a date string like below format "16-MAY-2005 01:26" 2)parsedate_tz function also failed if a date string
10
15535
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 Parse() and ParseExact(). I've been there and read all the information about using IFormatProviders, DateTimeStyles, CultureInfo....... Bottom...
1
4592
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 "dd/MM/yyyy" input as "01082003" convert to date value as, 01 Aug 2003 Example, User Defined Date Format as "yyyy,dd,MM"
0
1739
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 that the date string in 98 must be day/month/year and that in xp it must be month/day/year can somebody confirm this? Also they seem to drop the...
17
5247
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
13028
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 of type string cannot be converted to 'System.IFormatProvider' How can I do it in VB.NET ? Thanks.
2
11146
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") pArray is a variant array containing a date string at pArray(4, iRecord) in the format "yyyy/mm/dd"
3
7144
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 to autoformat the contents of text entries in a GUI. For numbers, I'm converting the text representation to the appropriate type (using atoi, atof,...
2
3217
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 prefer doing it in VB but how? Thanks, adh *** Sent via Developersdex http://www.developersdex.com ***
2
2755
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... "c:\\inetpub\\wwwroot\\TaxBusiness\\AnonymousAccess\\App_Themes" The folders in my website project are... Admin
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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...
0
8220
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
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
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
1185
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.