I'd like to find a simple... (I'm a simple person) procedure to
subtract a numerical number from a six char date string
YYYYMMDD and then convert back to a new date string.
I'm sure there's a way to do it, but the date modules haven't been
much help.
TIA
Ron 6 907
RLV wrote:
I'd like to find a simple... (I'm a simple person) procedure to
subtract a numerical number from a six char date string
YYYYMMDD and then convert back to a new date string.
I'm sure there's a way to do it, but the date modules haven't been
much help.
TIA
Ron
-- http://mail.python.org/mailman/listinfo/python-list
The datetime module has what you need.
It has methods (with examples) on building a datetime object from a
string, and it has a object named timedelta, and the ability to subtract
a timedelta from a time.
For instance, the time right now and the time exactly one day ago:
>>from datetime import * datetime.today()
datetime.datetime(2008, 7, 10, 13, 38, 48, 279539)
>>datetime.today()-timedelta(1)
datetime.datetime(2008, 7, 9, 13, 38, 50, 939580)
Gary Herron
On Thu, 10 Jul 2008 13:39:29 -0700, Gary Herron
<gh*****@islandtraining.comwrote:
>The datetime module has what you need.
It has methods (with examples) on building a datetime object from a string, and it has a object named timedelta, and the ability to subtract a timedelta from a time.
For instance, the time right now and the time exactly one day ago:
>from datetime import * datetime.today()
datetime.datetime(2008, 7, 10, 13, 38, 48, 279539)
>datetime.today()-timedelta(1)
datetime.datetime(2008, 7, 9, 13, 38, 50, 939580)
Gary Herron
Thanks Gary! This works great. Now all I need to know is how to
plug the date into the datetime object from a string.
Ron
RV wrote:
On Thu, 10 Jul 2008 13:39:29 -0700, Gary Herron
<gh*****@islandtraining.comwrote:
>The datetime module has what you need.
It has methods (with examples) on building a datetime object from a string, and it has a object named timedelta, and the ability to subtract a timedelta from a time.
For instance, the time right now and the time exactly one day ago:
>>>>from datetime import * datetime.today() >
datetime.datetime(2008, 7, 10, 13, 38, 48, 279539)
>>>>datetime.today()-timedelta(1) >
datetime.datetime(2008, 7, 9, 13, 38, 50, 939580)
Gary Herron
Thanks Gary! This works great. Now all I need to know is how to
plug the date into the datetime object from a string.
Use
*strptime*( date_string, format)
The format argument uses %-fields to describe how to pull data out of
the date_string.
It uses the same set of %-fields as the time modules strftime function
Gary Herron
Ron
-- http://mail.python.org/mailman/listinfo/python-list
RV wrote:
On Thu, 10 Jul 2008 13:39:29 -0700, Gary Herron
<gh*****@islandtraining.comwrote:
>The datetime module has what you need.
It has methods (with examples) on building a datetime object from a string, and it has a object named timedelta, and the ability to subtract a timedelta from a time.
For instance, the time right now and the time exactly one day ago:
>>>>from datetime import * datetime.today()
datetime.datetime(2008, 7, 10, 13, 38, 48, 279539)
>>>>datetime.today()-timedelta(1)
datetime.datetime(2008, 7, 9, 13, 38, 50, 939580)
Gary Herron
Thanks Gary! This works great. Now all I need to know is how to
plug the date into the datetime object from a string.
Ron
I really shouldn't do this until you have put forth at least a little effort...
Type the following into the Python interpreter:
>>>import datetime help(datetime.datetime.strptime)
Help on built-in function strptime:
strptime(...)
string, format -new datetime parsed from a string (like time.strptime()).
Note: Looking in Python manual or Googling for time.strptime (to get proper
format for YYYYMMDD)
dstr = "20070710"
dt = datetime.datetime.strptime(dstr, "%Y%m%d")
>>>dt
datetime.datetime(2008, 7, 10, 0, 0)
-Larry
Ron wrote:
Now all I need to know is how to
plug the date into the datetime object from a string.
You could use simple string manipulation:
>>import datetime a="20081031" d=datetime.date(int(a[0:4]),int(a[4:6]),int(a[6:8])) d
datetime.date(2008, 10, 31)
>>print d
2008-10-31
Greetings,
On Thu, 10 Jul 2008 20:04:27 -0400, RV <Ro**@Nospam.comwrote:
Gary, Larry, Michiel ,
Thanks very much, your helpful info has enabled me to get past a
learning bump.
Ron This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joannie Jae |
last post by:
Need a script to allow users to post their social events, and having a
devil of a time finding one. Some criteria:
• Users can post their own event, without requiring any kind of
registration. ...
|
by: Skip Montanaro |
last post by:
I wrote PEP 304, "Controlling Generation of Bytecode Files":
http://www.python.org/peps/pep-0304.html
quite awhile ago. The first version appeared in January 2003 in response to
questions...
|
by: RFox |
last post by:
I date back to the early days of the web when HTML was limited
but very managable, and have always maintained that hand-coding
HTML gives you far better control and cleaner HTML markup than
any...
|
by: Aing |
last post by:
Anyone knows what can be cause of this problem?
////////////////////////////////////////////////////////////
typedef struct _date_struct {
int date,month,year;
}date_struct;
Class Date {...
|
by: Randy Yates |
last post by:
Hi Folks,
I'm looking for something that is completely independent of the MSVC++
Dev Studio environment, something that will compile and run under
win32 using the mingw distribution. A class...
|
by: Larry |
last post by:
Does anyone use the 3rd party utility CodeRush for VStudio? If so then I
would like to see how well it is loved or hated. I have been using the
trial for a week and I have a mixed opinion about...
|
by: alexs |
last post by:
Hi,
I've got a Java stored procedure that I use to "register" systems on
our network. In the middle of it is a function that returns the 1st
free ip address in a class C network which is used in...
|
by: Ken Fine |
last post by:
I am using VS.NET 2008 and like it a lot. One of the very few things I don't
like is a bug that seems to spawn literally thousands of strings, one
after the other, on design view changes....
|
by: kr151080 |
last post by:
Ok so I am messing around with a program and have no idea how to go about doing this but here is the code for the class date....
public class Date
{
private int dMonth;
private int dDay;...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |