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

How to use date object

I am a newbie in python. And I would like to know how to create and
use the methods in date. Can someone please show me some code about
it. Thanks.
Jul 18 '05 #1
3 1220
marie wrote:
I am a newbie in python. And I would like to know how to create and
use the methods in date. Can someone please show me some code about
it. Thanks.

import datetime
year = 2004
month = 10
day = 22
d = datetime.datetime(year, month, day)
print d

etc.

// m
Jul 18 '05 #2
marie wrote:
I am a newbie in python. And I would like to know how to create and
use the methods in date. Can someone please show me some code about
it. Thanks.


The documentation for the datetime module is at
http://python.org/doc/2.3/lib/module-datetime.html

Some examples are in the Python Cookbook at
http://aspn.activestate.com/ASPN/Python/Cookbook/

but they aren't that useful as an intro / tutorial.

Here's some examples:
import datetime
today = datetime.date.today()
print today 2004-10-22 now = datetime.datetime.now()
print now 2004-10-22 20:58:30.308608 tomorrow = today + datetime.timedelta(days = 1)
print tomorrow 2004-10-23 now.hour 20 now.minute 58 now.second 30 now.microsecond 308608 today.year 2004 today.month 10 today.day 22 moonwalk = datetime.date(1969, 7, 20)
today - moonwalk datetime.timedelta(12878) delta = today - moonwalk
delta.days 12878

Andrew
da***@dalkescientific.com
Jul 18 '05 #3
Nice explaination and diagram about time at:
http://www.python.org/moin/WorkingWithTime

marie wrote:

I am a newbie in python. And I would like to know how to create and
use the methods in date. Can someone please show me some code about
it. Thanks.

Jul 18 '05 #4

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

Similar topics

7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
4
by: Christopher Benson-Manica | last post by:
I would like to subclass the built-in Date object to get additional functionality out of it, but the code below gives me an error something like "object is not a date object". Is there something...
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.