Compare date from db2 table to yesterday's Unix system date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare date from db2 table to yesterday's Unix system date
# 1  
Old 04-23-2008
Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine:

#!/usr/bin/ksh
count=`db2 -x "select count(*) from schema.tablename"`
echo "count"

I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename where PROCESS_DT(a datetime variable in tablename which is formatted as DATE9.) is equal to the today's unix system date - 1. I'm not sure of the proper syntax. Please help.

count=`db2 -x "select count(*) from schema.tablename where PROCESS_DT=UNIX system date-1"`
# 2  
Old 04-23-2008
A link that may helps you:

https://www.unix.com/shell-programmin...rday-date.html

Regards
# 3  
Old 04-23-2008
I now know how to find yesterdays date, however, I get an error message stating that the operands (PROCESS_DT and DATE_STAMP) are not compatible. PROCESS_DT is a DB2 date time variable with a DATE9 format. How can I declare DATE_STAMP to be a date time variable?

#!/usr/bin/ksh
DATE_STAMP=`TZ=CST+24 date +%y%m%d`
count=`db2 -x "select count(*) from schema.tablename where PROCESS_DT="$DATE_STAMP""`
echo "$count"
# 4  
Old 04-23-2008
I'm not familiar with db2 but you should do something like:

Code:
DATE_STAMP=`TZ=CST+24 date +%Y-%m-%d`
count=`db2 -x "select count(*) from schema.tablename where PROCESS_DT=DATE("$DATE_STAMP")`

I changed the date format and in the sql statement I convert the string in a date value.


Regards
# 5  
Old 04-23-2008
Franklin52,

After trying your suggestion, I got the following error:

SQL0183N A datetime arithmetic operation or a datetime scalar function has a result that is not within the valid range of dates. SQLSTATE=22008
# 6  
Old 04-23-2008
Sorry, I forgot to change the date format before running again. It worked, but returned a zero value for count. I'm trying to figure out why that happened when PROCESS_DT in the db2 table is equal to yesterday's date.
# 7  
Old 04-23-2008
I just tried changing the format of DATE_STAMP to +%m/%d/%Y to match the format of the values of PROCESS_DT (04/22/2008), but still got the same error as listed earlier.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Compare the system date with date from a text file

I get the date that's inside a text file and assigned it to a variable. When I grep the date from the file, I get this, Not After : Jul 28 14:09:57 2017 GMT So I only crop out the date, with this command echo $dateFile | cut -d ':' -f 2,4The result would be Jul 28 14:57 2017 GMT How do I... (3 Replies)
Discussion started by: Loc
3 Replies

4. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

5. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

6. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 Replies

7. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

8. Shell Programming and Scripting

Adding days to system date then compare to a date

Hi! I am trying to read a file and every line has a specific date as one of its fields. I want to take that date and compare it to the date today plus 6 days. while read line do date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD if ; then ...proceed commands ... (1 Reply)
Discussion started by: kokoro
1 Replies

9. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

10. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies
Login or Register to Ask a Question