473,412 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 2056
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.