Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
I have looked at the dateutils module and it has many comparison
methods, but they seem to only return the number of days or seconds.
Any ideas would be great!
Mike 8 1195
On May 10, 7:34 am, kyoso...@gmail. com wrote:
Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
I have looked at the dateutils module and it has many comparison
methods, but they seem to only return the number of days or seconds.
Ermmm ... what's wrong with
minutes = seconds / 60.0
hours = minutes / 60.0
? ky******@gmail. com wrote:
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
Not the most elegant piece of code on earth,
but this piece of code works for me (cut-and-pasted
directly from a working project, so doesn't
*exactly* match your requirement).
<code>
def deltastamp (now, then):
def pluralise (base, n):
if n 1:
return "%d %ss" % (n, base)
else:
return "%d %s" % (n, base)
if now then:
output_format = "%s ago"
delta = now - then
else:
output_format = "in %s"
delta = then - now
days = delta.days
if days <0:
wks, days = divmod (days, 7)
if wks 0:
output = pluralise ("wk", wks)
else:
output = pluralise ("day", days)
else:
mins, secs = divmod (delta.seconds, 60)
hrs, mins = divmod (mins, 60)
if hrs 0:
output = pluralise ("hr", hrs)
elif mins 0:
output = pluralise ("min", mins)
else:
output = pluralise ("sec", secs)
return output_format % output
</code>
TJG
On May 9, 5:12 pm, John Machin <sjmac...@lexic on.netwrote:
On May 10, 7:34 am, kyoso...@gmail. com wrote:
Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
I have looked at the dateutils module and it has many comparison
methods, but they seem to only return the number of days or seconds.
Ermmm ... what's wrong with
minutes = seconds / 60.0
hours = minutes / 60.0
?
I'm sure there is a hack for doing something like what you suggest,
but it would be messy. The problem is that I get a datetime object
returned and division really isn't something you can do to one of
those objects. Besides, if I had seconds returned, I would want to
multiply by 60, not divide.
Maybe I misunderstand you.
Mike
On May 10, 2:37 am, Tim Golden <m...@timgolden .me.ukwrote:
kyoso...@gmail. com wrote:
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
Not the most elegant piece of code on earth,
but this piece of code works for me (cut-and-pasted
directly from a working project, so doesn't
*exactly* match your requirement).
<code>
def deltastamp (now, then):
def pluralise (base, n):
if n 1:
return "%d %ss" % (n, base)
else:
return "%d %s" % (n, base)
if now then:
output_format = "%s ago"
delta = now - then
else:
output_format = "in %s"
delta = then - now
days = delta.days
if days <0:
wks, days = divmod (days, 7)
if wks 0:
output = pluralise ("wk", wks)
else:
output = pluralise ("day", days)
else:
mins, secs = divmod (delta.seconds, 60)
hrs, mins = divmod (mins, 60)
if hrs 0:
output = pluralise ("hr", hrs)
elif mins 0:
output = pluralise ("min", mins)
else:
output = pluralise ("sec", secs)
return output_format % output
</code>
TJG
Thanks for the advice. I think this will work for me with some minor
tweaking. If not, I will post again.
Mike
On Thu, 2007-05-10 at 11:52 -0700, ky******@gmail. com wrote:
I'm sure there is a hack for doing something like what you suggest,
but it would be messy. The problem is that I get a datetime object
returned and division really isn't something you can do to one of
those objects. Besides, if I had seconds returned, I would want to
multiply by 60, not divide.
If you subtract that datetime object from the current datetime, you'll
get a timedelta object that gives you the number of days and seconds
(and microseconds, if you care) between the two datetimes:
>>import datetime dt1 = datetime.dateti me(2007,5,1,12, 0,0) dt2 = datetime.dateti me.now() delta = dt2 - dt1 delta.days
9
>>delta.secon ds
11219
Now, if 60 seconds are one minute, 11219 seconds are how many minutes?
(Answer left as an exercise for the reader.)
Hope this helps,
--
Carsten Haese http://informixdb.sourceforge.net
On May 10, 1:52 pm, kyoso...@gmail. com wrote:
On May 9, 5:12 pm, John Machin <sjmac...@lexic on.netwrote:
On May 10, 7:34 am, kyoso...@gmail. com wrote:
Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
I have looked at the dateutils module and it has many comparison
methods, but they seem to only return the number of days or seconds.
Ermmm ... what's wrong with
minutes = seconds / 60.0
hours = minutes / 60.0
?
I'm sure there is a hack for doing something like what you suggest,
but it would be messy. The problem is that I get a datetime object
returned and division really isn't something you can do to one of
those objects. Besides, if I had seconds returned, I would want to
multiply by 60, not divide.
Maybe I misunderstand you.
Mike
Of course, after posting this, I felt very stupid...
On May 11, 4:52 am, kyoso...@gmail. com wrote:
On May 9, 5:12 pm, John Machin <sjmac...@lexic on.netwrote:
On May 10, 7:34 am, kyoso...@gmail. com wrote:
Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
I have looked at the dateutils module and it has many comparison
methods, but they seem to only return the number of days or seconds.
Ermmm ... what's wrong with
minutes = seconds / 60.0
hours = minutes / 60.0
?
I'm sure there is a hack for doing something like what you suggest,
but it would be messy. The problem is that I get a datetime object
returned and division really isn't something you can do to one of
those objects. Besides, if I had seconds returned, I would want to
multiply by 60, not divide.
Maybe I misunderstand you.
Maybe it's mutual -- hack? messy? multiply? Where I come from, 180
seconds is (180 / 60 = 3) minutes. 180 seconds * 60 is 10800 sixtieths-
of-a-second, which appears to be travelling away from a solution to
your problem.
You have *TWO* datetime objects, (say) appt_dt and now_dt.
delta =appt_dt - now_dt # delta is a timedelta object.
# calculate difference in minutes
mins = delta.days * 24 * 60 + delta.seconds // 60
Have you not read Tim Golden's response?
On May 10, 2:45 pm, John Machin <sjmac...@lexic on.netwrote:
On May 11, 4:52 am, kyoso...@gmail. com wrote:
On May 9, 5:12 pm, John Machin <sjmac...@lexic on.netwrote:
On May 10, 7:34 am, kyoso...@gmail. com wrote:
Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
10 minutes past your appointment
Either way, as each minute goes by, I need to increment it or
decrement it. I am having trouble finding a coherent way to take the
same date and compare just the number of minutes between them to find
the difference. Like if I have an appointment at 9:30 a.m. and the app
is loaded at 8 a.m., I need to know the number of minutes or hours and
minutes until the appointment.
I have looked at the dateutils module and it has many comparison
methods, but they seem to only return the number of days or seconds.
Ermmm ... what's wrong with
minutes = seconds / 60.0
hours = minutes / 60.0
?
I'm sure there is a hack for doing something like what you suggest,
but it would be messy. The problem is that I get a datetime object
returned and division really isn't something you can do to one of
those objects. Besides, if I had seconds returned, I would want to
multiply by 60, not divide.
Maybe I misunderstand you.
Maybe it's mutual -- hack? messy? multiply? Where I come from, 180
seconds is (180 / 60 = 3) minutes. 180 seconds * 60 is 10800 sixtieths-
of-a-second, which appears to be travelling away from a solution to
your problem.
You have *TWO* datetime objects, (say) appt_dt and now_dt.
delta =appt_dt - now_dt # delta is a timedelta object.
# calculate difference in minutes
mins = delta.days * 24 * 60 + delta.seconds // 60
Have you not read Tim Golden's response?
Yeah. I said I felt stupid. I'm sorry. I was looking at the problem
from the wrong direction.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: F |
last post by:
Hi
I have posted the question few days back about problem in inserting the
dates in SQL server and thankful to them who replied.
That was solved and this is a nice solution.
http://www.aspfaq.com/show.asp?id=2023
Now I am facing another problem.
I have to get data between two dates. That dates user has to provide and in
|
by: Duppypog |
last post by:
I'm trying to compare a date stored in a database with today's date using an
If statement, but it's not returning true. Example, value in database is
11/5/2003 with today being 11/6/2003. Can someone spot the problem?
Thanks,
Lynnette
Here's the code:
sSQL = "Select PWExpire FROM tblUsers where strUserName = '" & stUser & "'
AND strPassword = '" & hshPW & "'"
|
by: Philip Townsend |
last post by:
I am having difficulty with a simple routine as follows:
public static bool VerifyExpirationDate(DateTime date)
{
if(date>=DateTime.Now)return true;
else return false;
}
The problem is that when today's date is passed in, the method returns
false. Any ideas? Thanks!
|
by: JL |
last post by:
I need to compare two times. The problem I have is this:
In my code I create a time variable using the format statement below:
dim firstTime as DateTime
fistTime = Format("12:00:00 AM", "T")
I then store this in an Access database DateTime field.
When I read it back from the DatTime field. The values do not compare.
|
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 of the values comes
from the database, and for existing values it works fine, but if the
date doesn't exist (which will always be the condition when the user
first enters into the form) I am adding logic to my javascript like: if
(dbDate <...
| |
by: Working_Girl |
last post by:
Hi,
I have a database with insurance clients and their dependents (spouses
and children). We had a problem in the past with the twins and some of
them have been entered with one month difference in their dates of
birth, some of them have the same dates of births. I need to query
both cases. In the case where they are set up with one month
difference, the dates of birth has to be within 4 months of each other
and excluding the ones...
|
by: colincolehour |
last post by:
I am new to Python and am working on my first program. I am trying to
compare a date I found on a website to todays date. The problem I have
is the website only shows 3 letter month name and the date.
Example: Jun 15
How would I go about comparing that to a different date? The purpose of
my program is to load a webpage and see if the content on the front
page is fresh or stale as in older than a few days. Any help in the
right direction...
|
by: cheryl |
last post by:
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.......
|
by: dantebothermy |
last post by:
Is there a simple way to subtract the time from a datetime field, so when I compare dates, I'm always comparing the dates at 12:00 am?
I'd really prefer not to convert all my dates to strings.
Thanks,
Dante
|
by: jupi13 |
last post by:
i have this code..i don't know what where is the error in this one..it says data type mismatch.....
Dim Mydate As Date
Dim MydateString As String
MydateString = "Text1.Text"
Mydate = CDate(MydateString) ''it is highlighted in this line..
txtActCode = Mydate
i don't know what's wrong with this one..
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |