Hi,
how can I add calendar days in which it will exclude sundays?
ex: date today is MAY 1 then i will add 6 days, so it will return MAY 8 since sunday was excluded..
thanks guys....
3 1335
This is crude and done quick and dirty but here's an idea to get you started: -
>>> import datetime
-
>>> dt = datetime.date(2008, 5, 1)
-
>>> delta = 6
-
>>> if dt.weekday() > 7 - delta:
-
... delta += ( ( delta / 7 ) + [0, 1][bool(delta % 7)] )
-
...
-
>>> dt + datetime.timedelta(delta)
-
datetime.date(2008, 5, 8)
-
>>> delta = 20
-
>>> if dt.weekday() > 7 - delta:
-
... delta += ( ( delta / 7 ) + [0, 1][bool(delta % 7)] )
-
...
-
>>> dt + datetime.timedelta(delta)
-
datetime.date(2008, 5, 24)
-
>>>
That's not perfect but it's very close... only a minor modification to fix
This is crude and done quick and dirty but here's an idea to get you started: -
>>> import datetime
-
>>> dt = datetime.date(2008, 5, 1)
-
>>> delta = 6
-
>>> if dt.weekday() > 7 - delta:
-
... delta += ( ( delta / 7 ) + [0, 1][bool(delta % 7)] )
-
...
-
>>> dt + datetime.timedelta(delta)
-
datetime.date(2008, 5, 8)
-
>>> delta = 20
-
>>> if dt.weekday() > 7 - delta:
-
... delta += ( ( delta / 7 ) + [0, 1][bool(delta % 7)] )
-
...
-
>>> dt + datetime.timedelta(delta)
-
datetime.date(2008, 5, 24)
-
>>>
That's not perfect but it's very close... only a minor modification to fix
yeah much thanks for this.. i will do some modification..
Hey try this one !! hope this suits your requirement
I had a workaround with the time module - import time
-
import string ,sys
-
-
class workalday:
-
-
def __init__(self):
-
-
self.secperday=86400
-
-
def addtime(self):
-
""" Computations with epoch time working with dates after 1970"""
-
-
print "Provide with date in format dd/mm/yyyy to compute Number of sundays till then "
-
sys.stderr.write("Else provide with number of days for computation: ")
-
self.uinput=raw_input()
-
if '/' in self.uinput :
-
self.fomats(1)
-
else :
-
print ("Computation for %s days from present date" %self.uinput)
-
self.fomats(2)
-
print ("Expected %d/%d/%d"%(self.lastdate,self.lastmonth,self.lastyear))
-
-
def deadday(self,dd):
-
""" Computation of sundays"""
-
updatetime = 0
-
sdays = int(dd)
-
for i in range(sdays):
-
updatetime = updatetime + self.secperday
-
if time.localtime(self.presentsec + updatetime)[6] == 6:
-
sdays = sdays + 1
-
-
return sdays
-
-
def fomats(self,state):
-
-
""" Compute the sec and formated dates from actual to specified"""
-
self.presentsec = time.time()
-
self.pform= time.localtime()
-
if state == 2 :
-
""" If number of days specified"""
-
sunday = self.deadday(self.uinput)
-
self.display(sunday)
-
-
if state == 1 :
-
""" If date computations specified to date"""
-
frdate=string.split(self.uinput,'/')
-
consdate = tuple([int(frdate[2]),int(frdate[1]),int(frdate[0]),self.pform[3],self.pform[4],self.pform[5],self.pform[6],self.pform[7],self.pform[8]])
-
finsec = time.localtime(time.mktime(consdate))
-
diffdays = int(round((time.mktime(consdate) - self.presentsec ) / self.secperday))
-
sunday = self.deadday(diffdays)
-
print ("The Number of sundays that will be excuded: %d" %sunday)
-
-
def display(self,sdays):
-
-
self.lastyear = time.localtime(self.presentsec + (sdays*self.secperday))[0]
-
self.lastmonth = time.localtime(self.presentsec + (sdays*self.secperday))[1]
-
self.lastdate = time.localtime(self.presentsec + (sdays*self.secperday))[2]
-
-
if __name__=='__main__':
-
-
obj = workalday()
-
obj.addtime()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: androtech |
last post by:
Hello,
I'm looking for a function that returns a date range for a specified week
number of the year.
I'm not able to find functions like this anywhere. Any pointers/help would
be much...
|
by: rhino |
last post by:
This worked before October now it does not work. I think I know where the
trouble is but I don't know how to fix it.
function findVerse()
{
var d = new Date();
var str;
if( (...
|
by: Deano |
last post by:
Hi,
I generate a report using two dates (From and To). I notice if I enter
01/10/2003 that it is interpreted by Access as 10/01/2003 i.e 10th January
rather than 1st October as I intended.
...
|
by: Steve Elliott |
last post by:
I have a query set up to gather together data between two specified dates.
Shown in the query column as:
Between #24/09/2004# And #01/10/2004#
Is it possible to enter several different date...
|
by: Khurram |
last post by:
I have a problem while inserting time value in the datetime Field.
I want to Insert only time value in this format (08:15:39) into the SQL
Date time Field.
I tried to many ways, I can extract...
|
by: rohayre |
last post by:
Im a long time java developer and actually have never done anything
with java scripting. I'd like to write a short simple script for
calculating a date in the future based on today's date and a...
|
by: Luvin lunch |
last post by:
Hi,
I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.
I would like to use a...
|
by: user |
last post by:
Hi,
Let's say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
Date1. 21-Nov-2006 09:00:00 PM
|
by: sixdeuce62 |
last post by:
Hello,
I am trying to create a query that will prompt me to enter the
parameter value if beginning date and ending date.
I have created everything I need in the query, but I have to manually
go...
|
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: 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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |