473,399 Members | 4,177 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,399 software developers and data experts.

Date issue on interger field

I currently have a interger field with this format (YYYYMMDD) Example 20071118

I want to automate a weekly report Sun - Sat, therefore do not want to hard code the date. I want to say (Current Date - 7 days).

I have tried multiple things but they do not work.

Please help!

Thank YOU
Nov 19 '07 #1
5 1703
docdiesel
297 Expert 100+
Hi,

"Current Date - 7 days" only works on date or timestamp columns. If you stick to your integer field, you need to transform this date value to integer like:

Expand|Select|Wrap|Line Numbers
  1. ... where
  2.   my_int_date >=( year(Current Date - 7 days) * 10000
  3.                + month(Current Date - 7 days) * 100
  4.                +   day(Current Date - 7 days) * 1 )
Regards, Bernd
Nov 20 '07 #2
Hi,

"Current Date - 7 days" only works on date or timestamp columns. If you stick to your integer field, you need to transform this date value to integer like:

Expand|Select|Wrap|Line Numbers
  1. ... where
  2.   my_int_date >=( year(Current Date - 7 days) * 10000
  3.                + month(Current Date - 7 days) * 100
  4.                +   day(Current Date - 7 days) * 1 )
Regards, Bernd
Wow!! It works.

Please explain how it works.

For current date I am using Nov 20. So if I use the formula you gave I get

Year(20-7)*1000=13000
Month(20-7)*100=1300
Day(20-7)*1=13

13000+1300+13=14313 (How does 14313 equal Nov 13 ?

Thanks again. Your a life Saver!
Nov 20 '07 #3
docdiesel
297 Expert 100+
Hi,

glad to hear you're saved. But your calculation is slightly wrong. Assumed today is the 20th of november, then current_date() would give '2007-11-20' as result. Put this into your calculation to see what happens:

Expand|Select|Wrap|Line Numbers
  1. -> current_date() - 7 days 
  2. =    '2007-11-20' - 7 days
  3. =    '2007-11-13'
  4.  
  5.  Year( '2007-11-13' ) * 10000 = 2007 * 10000 = 20070000
  6. Month( '2007-11-13' ) *   100 =   11 *   100 =     1100
  7.   Day( '2007-11-13' ) *     1 =   13 *     1 =       13
  8. -------------------------------------------------------
  9.                                          Sum = 20071113
  10.  
Regards, Bernd
Nov 21 '07 #4
Hi,

glad to hear you're saved. But your calculation is slightly wrong. Assumed today is the 20th of november, then current_date() would give '2007-11-20' as result. Put this into your calculation to see what happens:

Expand|Select|Wrap|Line Numbers
  1. -> current_date() - 7 days 
  2. =    '2007-11-20' - 7 days
  3. =    '2007-11-13'
  4.  
  5.  Year( '2007-11-13' ) * 10000 = 2007 * 10000 = 20070000
  6. Month( '2007-11-13' ) *   100 =   11 *   100 =     1100
  7.   Day( '2007-11-13' ) *     1 =   13 *     1 =       13
  8. -------------------------------------------------------
  9.                                          Sum = 20071113
  10.  
Regards, Bernd

That is really cool! Awesome.

My only concern is when I run the report on January 6, 2008 and go back 7 days, is the system smart enough to know I want December 30 to 31st and January 1st to 5th. ?

Have a great Thanksgiving!
Nov 21 '07 #5
docdiesel
297 Expert 100+
My only concern is when I run the report on January 6, 2008 and go back 7 days, is the system smart enough to know I want December 30 to 31st and January 1st to 5th. ?
Yes, it is. That's why there's the "+- x days/minutes/etc" possibility. After all, inside DB2 date, time and datestamp fields are nothing else than integers. But just not the way you seem to need them.
Have a great Thanksgiving!
Thank you, the same to you.
Nov 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's...
4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
4
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
2
by: Douglas | last post by:
I have a Vehicle MOT field in my table which i have as a Date field I dont really want to hold the year, just 'dd mmm' as MOTs are the same date every year. I have the field on my form as a...
2
by: Matt | last post by:
I have a number of TextBox controls bound to date fields in my application, and have come across a disconcerting issue: When you are entering data into the bound field, if you enter any string that...
2
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my...
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
2
by: Brad Pears | last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend . I am having a bit of problems with date variables... Here is the scenario... I have a table that includes a couple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
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
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,...

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.