Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 31-07-2009
Member
 
Join Date: May 2008
Posts: 13
PHP Need to subtract day from MySQL date

Hi,

I a working with PHP MySQL environment & I need to subtract a day or say 2 days from a date. Now the problem is how to apply the logic to deduct days from start_date?
PHP Need to subtract day from MySQL date
Can anyone please help me out?
Thanks in advance.
Reply With Quote
  #2  
Old 31-07-2009
Member
 
Join Date: Apr 2008
Posts: 21
Re: PHP Need to subtract day from MySQL date

Try this:

Code:
$date = "1999-05-22";
$newdate = strtotime ( '-3 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );
 
echo $newdate;
Reply With Quote
  #3  
Old 31-07-2009
Member
 
Join Date: May 2008
Posts: 21
Re: PHP Need to subtract day from MySQL date

You can also use Use DATE_SUB in the WHERE clause.

DATE_SUB(date,INTERVAL expr unit)
Reply With Quote
  #4  
Old 31-07-2009
Member
 
Join Date: May 2008
Posts: 41
Re: PHP Need to subtract day from MySQL date

Mysql Date Subtract

Mysql Date Subtract is used to find the date between the current date and the date before the current date.

We use select DATE_SUB(curdate(),INTERVAL 1DAY) that return you date one day before the current date.
DATE_SUB(curdate(),INTERVAL DAY) : The Query is used to return the date before the current date. The INTERVAL is used to subtract the number of days specified in interval from the current date

Query to subtract from date

Code:
select DATE_SUB(curdate(), INTERVAL 1 DAY);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "PHP Need to subtract day from MySQL date"
Thread Thread Starter Forum Replies Last Post
How to subtract cells of two different Spreadsheet Kaesav MS Office Support 2 17-02-2012 05:31 PM
unable to subtract value in ActionScript program KADRI Software Development 4 02-02-2010 07:57 PM
Mysql Error : Can't connect to local mysql server through socket ' var lib mysql mysql.sock' 2 roshan45 Software Development 3 07-11-2009 09:36 PM
PHP : Increment date in mysql Warner Software Development 3 02-07-2009 06:23 PM
MySQL date & time function. Amaresh Software Development 2 19-06-2009 02:49 PM


All times are GMT +5.5. The time now is 12:05 PM.