SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add 7 days to a date variable

    I'm posting a form with a date variable in it (date_start). The posted date format is YYYYMMDD.

    When writing to the datebase, I want to add 7 days to this date and write it to the date_end column.

    Basically, I want to write date_end = date_start + 7 days.

    I have tried several PHP and MySQL solutions, weeded through countless forum postings and not found the solution that works.

    My latest try is this:

    INSERT INTO table ( date_end )
    VALUES (
    DATE_ADD( '$date_start', INTERVAL 7
    DAY )

    but it gives me an error:
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

    My server is running PHP 4.4.9 and MYSQL 5.0.67,

    Thanks for any help.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Echo the query and check that $date_start actually contains a value

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, my $date_start was empty because of a typo further up in the code. Stupid mistake. Thanks for your help.


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
  •