Basic date/time math 
Author Message
 Basic date/time math
Hi,
I'm having trouble with some basic date/time math. What I need to do
is:
  - subtract one hour of the current date/time;
  - subtract one year of a given date.

I used to that in Sybase using a built-in function, but I can't figure
out how to do these 2 operations in Informix. Can anyone give me a
hint ?

Thanks in advance,

  -- Sibele

Sibele V. Oliveira



Tue, 22 Jun 2004 22:41:28 GMT
 Basic date/time math

Try this:

date1 is a date column
dt1 is a datetime year to minute column

For the year ....
select date1 - 1 units year
from t1;

For the hour ...
select dt1 - 1 units hour
from t1;

--
Jay Aymond
Community Coffee Company
Baton Rouge, LA
www.communitycoffee.com

Quote:
> Hi,
> I'm having trouble with some basic date/time math. What I need to do
> is:
>   - subtract one hour of the current date/time;
>   - subtract one year of a given date.

> I used to that in Sybase using a built-in function, but I can't figure
> out how to do these 2 operations in Informix. Can anyone give me a
> hint ?

> Thanks in advance,

>   -- Sibele

> Sibele V. Oliveira



Tue, 22 Jun 2004 23:22:25 GMT
 Basic date/time math

Subtract 1 hour from current time/date:

var DATETIME YEAR TO SECOND
LET var = CURRENT YEAR TO SECOND - 1 UNITS HOUR

Subtract 1 year from current time/date:

var DATETIME YEAR TO SECOND
LET var = CURRENT YEAR TO SECOND - 1 UNITS YEAR

Months, days, hours, minutes, seconds... pretty much all follow the same
scheme :)

Quote:
-----Original Message-----

Sent: Friday, January 04, 2002 9:41 AM

Subject: Basic date/time math

Hi,
I'm having trouble with some basic date/time math. What I need to do
is:
  - subtract one hour of the current date/time;
  - subtract one year of a given date.

I used to that in Sybase using a built-in function, but I can't figure
out how to do these 2 operations in Informix. Can anyone give me a
hint ?

Thanks in advance,

  -- Sibele

Sibele V. Oliveira



Tue, 22 Jun 2004 23:19:01 GMT
 Basic date/time math
Quote:
----- Original Message -----

| Hi,
| I'm having trouble with some basic date/time math. What I need to do
| is:
|   - subtract one hour of the current date/time;

current - 1 units hour

|   - subtract one year of a given date.

today - 1 units yers

or the long one

mdy(month(today), day(today), year(today) - 1)

Use your date variable in place of today

|
| I used to that in Sybase using a built-in function, but I can't figure
| out how to do these 2 operations in Informix. Can anyone give me a
| hint ?
|
| Thanks in advance,
|
|   -- Sibele
|
| Sibele V. Oliveira



Tue, 22 Jun 2004 23:45:54 GMT
 Basic date/time math

Quote:

>----- Original Message -----

>| I'm having trouble with some basic date/time math. What I need to do
>| is:
>|   - subtract one hour of the current date/time;

>current - 1 units hour

>|   - subtract one year of a given date.

>today - 1 units yers

>or the long one

>mdy(month(today), day(today), year(today) - 1)

>Use your date variable in place of today

>| I used to that in Sybase using a built-in function, but I can't figure
>| out how to do these 2 operations in Informix. Can anyone give me a
>| hint ?

All the answers I saw were correct but incomplete.  Subtracting an hour
won't ever hurt you.  Subtracting one year will hurt you when the date
you start with is leap day in a leap year (eg 2000-02-29).  Then the
arithmetic will fail with an error.  Handling that will be a pain -
stored procedure time.

--

Guardian of DBD::Informix 1.00.PC1 -- see http://www.cpan.org/
#include <disclaimer.h>



Fri, 25 Jun 2004 13:04:09 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. MySQL ODBC - Coverting Access date/time type to MySQL date/time type

2. Feature-request: allowing the date/time type to accept ISO8601 compliant date/time combinations on input

3. java Date/Time-->MSAccess Date/Time?

4. ADO with Access Date/Time field not storing the time, just the date

5. Getting Date/Time from LAN Machine and Setting Date/Time on Client

6. how to change dates or times in a oracle date time field

7. Calculate difference between start date and time and end date and time

8. Unix time/date => Pick time/date

9. retrieve DOS file's date and time using BASIC

10. math in query vs math in app

11. no math found in shared library path java/math/BigInteger

12. Visual Basic Math Libs


 
Powered by phpBB® Forum Software