The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare files in the system with last modified date bsandeep_80 Linux 6 01-14-2008 08:56 PM
How can i get the yesterday's date in YYYYMMDD format prasadsr HP-UX 4 01-19-2007 05:52 AM
get yesterday's date? fedora Shell Programming and Scripting 1 12-08-2006 11:28 AM
Yesterday's date function ssmiths001 UNIX for Dummies Questions & Answers 4 01-11-2005 06:06 AM
Yesterday's date ssmiths001 UNIX for Dummies Questions & Answers 2 11-22-2004 05:46 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 22
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"`
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-23-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,965
A link that may helps you:

Getting yesterday DATE

Regards
Reply With Quote
  #3 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 22
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"
Reply With Quote
  #4 (permalink)  
Old 04-23-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,965
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
Reply With Quote
  #5 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 22
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
Reply With Quote
  #6 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 22
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.
Reply With Quote
  #7 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 22
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0