472,980 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 software developers and data experts.

Year, Month, Day functions

Tim
Hello Everyone

I'm sure that there is a simple answer to this but I was wondering if
there was an elegant way to change the definition of the functions like
year, month and day such that they are effectively run for a different
time zone without changing the server time/timezone. When you run say:

select day(transaction_time),
count(*)
from transaction
where transaction_time >= current timestamp - 10 days

it will use the current timezone. So if we have two machines one in
London and one in NY and we run the same query on each server we'd get
different results due to NY time being 5 hours behind London time. Or
as in our case we have a single server handling clients in multiple
timezones each of which want to have reports come out in their local
time.

One way to do this is some time arithmetic before passing it on to the
date functions (i.e. day(transaction_time - 5 hours) but that wouldn't
let DB2 use the indexes defined on transaction_time assuming there was
one IIRC.

Has anyone got any ideas how this can be done?

thanks in advance
tim

Nov 12 '05 #1
4 2041
In article <11**********************@g47g2000cwa.googlegroups .com>,
Tim (ku******@gmail.com) says...
Hello Everyone

I'm sure that there is a simple answer to this but I was wondering if
there was an elegant way to change the definition of the functions like
year, month and day such that they are effectively run for a different
time zone without changing the server time/timezone. When you run say:

select day(transaction_time),
count(*)
from transaction
where transaction_time >= current timestamp - 10 days

it will use the current timezone. So if we have two machines one in
London and one in NY and we run the same query on each server we'd get
different results due to NY time being 5 hours behind London time. Or
as in our case we have a single server handling clients in multiple
timezones each of which want to have reports come out in their local
time.

One way to do this is some time arithmetic before passing it on to the
date functions (i.e. day(transaction_time - 5 hours) but that wouldn't
let DB2 use the indexes defined on transaction_time assuming there was
one IIRC.

Has anyone got any ideas how this can be done?

thanks in advance
tim


Maybe you can do some arithmetic using the CURRENT TIMEZONE value?
Nov 12 '05 #2
Tim
Hi Gert

What did you have in mind for this? CURRENT TIMEZONE isn't something
that can be updated and I would've thought that doing column level
arithmetic would prevent DB2 from using indexes on that column? I seem
to recall using column functions having this effect.

thanks
tim

Nov 12 '05 #3
I would say the database design does not match the requirements. The
requirements are global consistency, where the design is for
region-based timings. To me, the answer would be to store times in GMT,
so the query would return the same result set no matter where it has
been executed. It would then be up to the application to tranlate it
into local time.

OTOH, perhaps a COLUMN could be ADDed to the TABLE defined as GENERATED
ALWAYS AS day(transaction_time - 5 hours). An INDEX would then be added
to the GENERATED COLUMN.

If no changes are to be made, the query could be changed to use a
BETWEEN operator, without using DAY() at all.

Nov 12 '05 #4
In article <11**********************@g49g2000cwa.googlegroups .com>,
Tim (ku******@gmail.com) says...
Hi Gert

What did you have in mind for this? CURRENT TIMEZONE isn't something
that can be updated and I would've thought that doing column level
arithmetic would prevent DB2 from using indexes on that column? I seem
to recall using column functions having this effect.

thanks
tim


Hi Tim,
You can use the CURRENT TIMEZONE variable to insert the GMT (or UTC
as it is being called now) into the database. Offcourse you also need
to take care of adding it when retrieving the date again but it makes
it a lot easier to compare them.

kind regars, Gert
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken Fine | last post by:
I want my application to maintain a directory tree based on months and years, e.g.: 2004 January file file file February file
4
by: Ken Fine | last post by:
Using ASP, I want to display a series of records grouped by nested years and months, e.g.: 2004 December Record1 Record2 Record3 November Record4
8
by: Zero.NULL | last post by:
Hi, We are using Month-year tables to keep the history of long transaction of our application. For example: We capture the details of a certain action in table...
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
20
by: Laguna | last post by:
Hi Gurus, I want to find the expiration date of stock options (3rd Friday of the month) for an any give month and year. I have tried a few tricks with the functions provided by the built-in...
19
by: Ricardo Perez Lopez | last post by:
Hello everyone: I'm a PostgreSQL newbie, working now with dates, times, timestamps and intervals. I have three questions about the above: FIRST: --------
1
by: Helge's | last post by:
I have an orderdatabase with DATE and SALES as one of the fields in a table. How would the SQL look like if I want a table with MONTH, 2006, 2005, DIFFERENCE. I think when I have the field DATE I...
2
by: owz | last post by:
Ok, I am making a program (java class file) 2 work out if a date entered is valid or invalid for the day, month year, and for leap years.. dd/mm/yyyy . I seem 2 have gotten it 2 validate the year...
5
by: Kasrav | last post by:
I have another problem hopeful am not bothering you guys too much if u can help that would be wonderful. I have this code here def year2(): print'This program validates days and months of the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.