if statement with dates

Reply

Join Date: Mar 2008
Posts: 42
Reputation: aran87 is an unknown quantity at this point 
Solved Threads: 0
aran87 aran87 is offline Offline
Light Poster

if statement with dates

 
0
  #1
Apr 25th, 2008
hello, im using a delete function but some how i want to use an if statement; for example if the current server date matches the date from a row from a database table and if the date is 2days from the current date it can't be delete.

  1. Delete from House where rooms='10';
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: aran87 is an unknown quantity at this point 
Solved Threads: 0
aran87 aran87 is offline Offline
Light Poster

Re: if statement with dates

 
0
  #2
Apr 27th, 2008
can it be an if statement??
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if statement with dates

 
0
  #3
Apr 27th, 2008
i prefer to use php rather than hard coding in mysql as date var can be set and change easier

## php
$del_date = date('Y-m-d', strtotime(' + 2 days')); Delete from House where rooms='10' and roomdate > '$del_date'

## mysql
Delete from House where rooms='10' and roomdate < DATE_SUB(CURDATE(), INTERVAL 2 DAY)
Last edited by peter_budo; Apr 29th, 2008 at 9:23 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if statement with dates

 
0
  #4
Apr 27th, 2008
php should be -2 days
## php
$del_date = date('Y-m-d', strtotime(' -2 days')); Delete from House where rooms='10' and roomdate < '$del_date'
Last edited by peter_budo; Apr 29th, 2008 at 9:25 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: aran87 is an unknown quantity at this point 
Solved Threads: 0
aran87 aran87 is offline Offline
Light Poster

Re: if statement with dates

 
0
  #5
Apr 27th, 2008
hello but how do i get current date? to be implemented into that code??
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if statement with dates

 
0
  #6
Apr 27th, 2008
what current date are u talking about?

current date is auto? its like now()
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: aran87 is an unknown quantity at this point 
Solved Threads: 0
aran87 aran87 is offline Offline
Light Poster

Re: if statement with dates

 
0
  #7
Apr 27th, 2008
hello im on about current date so how would i implement all that code how would it be?

$del_date = date('Y-m-d', strtotime(' -2 days'));
Delete from House where rooms='10' and roomdate < '$del_date'
nothing needs to go in sql right?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if statement with dates

 
0
  #8
Apr 27th, 2008
nothing needs to go into sql just as long as you have a date to del from like roomdate.

$del_date = date('Y-m-d', strtotime(' -2 days')); // this makes the date 2 days ago eg. 2008-04-25


Delete from House where rooms='10' and roomdate < '$del_date'
// find rooms with 10 and all room dates less than $del_date

run query
Delete from House where rooms='10' and roomdate < '2008-04-25'
house1 - 10 - 2008-04-26
house2 - 10 - 2008-04-11 [ deleted ]
house3 - 5 - 2007-04-22
house4 - 7 - 2008-04-25
house5 - 10 - 2008-04-24 [ deleted ]
house6 - 10 - 2008-04-25
Last edited by peter_budo; Apr 29th, 2008 at 9:25 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: aran87 is an unknown quantity at this point 
Solved Threads: 0
aran87 aran87 is offline Offline
Light Poster

Re: if statement with dates

 
0
  #9
Apr 27th, 2008
how can i add some sort of message saying you can not delete this record and a message saying deleted?? also i dont want the user to be able to input a date they only input an id and click submit and the code you have given requires a date to be entered by a user or does it?? cheers
Last edited by aran87; Apr 27th, 2008 at 5:48 pm. Reason: error
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if statement with dates

 
0
  #10
Apr 27th, 2008
1.
$del_date = date('Y-m-d', strtotime(' -2 days')); // this makes the date 2 days ago
eg. 2008-04-25
you set the date. it is not set by the user.



run query
Delete from House where rooms='10' and roomdate < '2008-04-25'
house1 - 10 - 2008-04-26
house2 - 10 - 2008-04-11 [ deleted ]
house3 - 5 - 2007-04-22
house4 - 7 - 2008-04-25
house5 - 10 - 2008-04-24 [ deleted ]
house6 - 10 - 2008-04-25
this was an example of wat would happen. the date at end is an example. the date would come from quote 1 - $del_date

---------------

  1. $del_date = date('Y-m-d', strtotime(' -2 days'));
  2.  
  3. $sql = "DELETE FROM House where id='".mysql_real_escape_string($id)."' and roomdate < '$del_date'";
  4. $query = mysql_query($sql) ;
  5. if(mysql_affected_rows()>0){ deleted }else{ not deleted }
Last edited by amigura; Apr 27th, 2008 at 6:18 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC