Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL - Find past seven days

Status
Not open for further replies.

youthman

Programmer
Apr 28, 2004
49
US
Greetings to all . . . I have a SQL problem.

I have an SQL database that saves the date of the current entry as a standart VarChar. The format is yyyy-mm-dd

What I want to do is to extract the current date from the server, and search for the items that have been added to the database in the past 7 days.

Question 1: I can extract the time and date from the server, and can get it formated to the correct current date, but how do I take into account the change in month on the date. For example . . . If the current date is 2004-07-02, I need everything from 2004-06-26 to 2004-07-02. Does Perl have a built in way of subtracting days?

Question 2: Is there an easy Select statement that will select all the records between those date? (Keep in mind that the date column is NOT set up as a date, but as a VarChar?)

Any help would be great!!

Thanks

The Youthman
 
Could you use dates in the format YYYYMMDD?
Code:
$mydate="20040610";
@dates=("20040715","20040715","20040716","20040607" ...);
foreach (@dates) {
 if ($mydate le $_) {
   print "$_ is since $mydate;
 } else {
   print "\t\t$_ is before $mydate";
 }
}
Hope this makes sense
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Actually it should even work with YYYY-MM-DD, because its comparing each component, as long as the seperators are indentical.
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top