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 ?

-- 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 ?

>   -- 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 ?

-- 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 ?
|
|
|   -- 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

 Page 1 of 1 [ 5 post ]

Relevant Pages