Results 1 to 4 of 4

Thread: PHP Need to subtract day from MySQL date

  1. #1
    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.

  2. #2
    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;

  3. #3
    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)

  4. #4
    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);

Similar Threads

  1. How to subtract cells of two different Spreadsheet
    By Kaesav in forum MS Office Support
    Replies: 2
    Last Post: 17-02-2012, 05:31 PM
  2. unable to subtract value in ActionScript program
    By KADRI in forum Software Development
    Replies: 4
    Last Post: 02-02-2010, 07:57 PM
  3. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  4. PHP : Increment date in mysql
    By Warner in forum Software Development
    Replies: 3
    Last Post: 02-07-2009, 06:23 PM
  5. MySQL date & time function.
    By Amaresh in forum Software Development
    Replies: 2
    Last Post: 19-06-2009, 02:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,565,322.02517 seconds with 16 queries