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

Printing date a file

In Python how would you print the date in a file, I
have a logging program written in python and for each
new recorded added to the file, I would like to print
the
date, something like this below:

08/24/2004 or 08-24-2004

--
Kory Wheatley

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
Jul 18 '05 #1
6 1498
Kory Wheatley wrote:
In Python how would you print the date in a file, I
have a logging program written in python and for each
new recorded added to the file, I would like to print
the
date, something like this below:

08/24/2004 or 08-24-2004

--
Kory Wheatley

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail


Kory,
Works. Maybe a better way.
wes
import datetime
d = datetime.datetime(2004,1,1).today()
d datetime.datetime(2004, 8, 24, 12, 29, 25, 784935) d.year 2004 d.month 8 d.day

24

Jul 18 '05 #2
Take a look at time.strftime()

HTH,
Larry Bates
Syscon, Inc.

"Kory Wheatley" <wh**************@yahoo.com> wrote in message
news:ma**************************************@pyth on.org...
In Python how would you print the date in a file, I
have a logging program written in python and for each
new recorded added to the file, I would like to print
the
date, something like this below:

08/24/2004 or 08-24-2004

--
Kory Wheatley

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

Jul 18 '05 #3
In article <ma**************************************@python.o rg>,
Kory Wheatley <wh**************@yahoo.com> wrote:
In Python how would you print the date in a file, I
have a logging program written in python and for each
new recorded added to the file, I would like to print
the
date, something like this below:

08/24/2004 or 08-24-2004


import time

print time.strftime("%m/%d/%Y or %m-%d-%Y")

See also:
http://www.python.org/doc/2.3.4/lib/module-time.html
Cheers,
-M

--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
Jul 18 '05 #4
I would use the "International Date Format (ISO 8601)"

CCYY-MM-DD (2004-08-24)

Regards,
Bernd Kaiser

Kory Wheatley wrote:
In Python how would you print the date in a file, I
have a logging program written in python and for each
new recorded added to the file, I would like to print
the
date, something like this below:

08/24/2004 or 08-24-2004

--
Kory Wheatley

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

Jul 18 '05 #5
Kory Wheatley <wh**************@yahoo.com> wrote in message news:<ma**************************************@pyt hon.org>...
In Python how would you print the date in a file, I
have a logging program written in python and for each
new recorded added to the file, I would like to print
the
date, something like this below:

08/24/2004 or 08-24-2004

--
Kory Wheatley


Read up on the time module, specifically strftime.

Daniel Bickett
Jul 18 '05 #6
Kory Wheatley wrote:
In Python how would you print the date in a file...


Here's my favorite way:
import datetime
datetime.date.today().isoformat()

'2004-08-24'

Jeffrey
Jul 18 '05 #7

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

Similar topics

10
by: Brian Hanson | last post by:
Hi, I am trying to programmatically print a pdf file via an asp.net application. I have seen other postings that mention the following code used or something similar to it in a vb.net app. ...
3
by: stan | last post by:
I am working on some documentation in html format and I would really like to display the date the html file, itself was modified. I am writing my documentation in vi and the html server involved is...
0
by: Niyazi | last post by:
Hi all, This my aspx page first line of code. <%@ Page CodeBehind="index.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="TB.index" %> Than inside head tag I have following script(s)...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
1
by: Earl Anderson | last post by:
Using WinXP & AccessXP, I'd like to automatically have the records that I've just printed in a report automatically updated to have the 'print date & time' immediately inserted into a 'Date/Time'...
5
by: Tom | last post by:
I am converting an old application that was printing directly to a specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
1
by: belinda | last post by:
I have used the ff command but only get the date printout and have no clue whats wrong: 'Printing function ' - opening a Word template with bookmarks ' - read bookmarks list from template and...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
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: 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
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
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
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.