The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-15-2008 12:56 AM
How can i get the yesterday's date in YYYYMMDD format prasadsr HP-UX 4 01-19-2007 09:52 AM
get yesterday's date? fedora Shell Programming and Scripting 1 12-08-2006 03:28 PM
Yesterday's date function ssmiths001 UNIX for Dummies Questions & Answers 4 01-11-2005 10:06 AM
Yesterday's date ssmiths001 UNIX for Dummies Questions & Answers 2 11-22-2004 09:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2008
sasaliasim sasaliasim is offline
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"`
  #2 (permalink)  
Old 04-23-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
A link that may helps you:

Getting yesterday DATE

Regards
  #3 (permalink)  
Old 04-23-2008
sasaliasim sasaliasim is offline
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"
  #4 (permalink)  
Old 04-23-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
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 (permalink)  
Old 04-23-2008
sasaliasim sasaliasim is offline
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
  #6 (permalink)  
Old 04-23-2008
sasaliasim sasaliasim is offline
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.
  #7 (permalink)  
Old 04-23-2008
sasaliasim sasaliasim is offline
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.
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0