Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post How to Insert DATE in my SQL using PHP

    Need Help!!
    I have tried it but It is not working..
    //dob column is of DATE datatype
    Code:
    $dob= $_POST['year'] . '-' . $_POST['month'] . '-' .$_POST['day'];
    $query=mysql_query("INSERT INTO user(dob) VALUES('$dob')",$con);

  • #2
    New Coder
    Join Date
    Apr 2012
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Have you tried using the [icode]date[\icode] handler ...
    [icode]$year= date ('yyyy',$year);[\icode]
    I am brand new to coding in PHP, but I think this may work...

  • #3
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Saima Nazir View Post
    Need Help!!
    I have tried it but It is not working..
    //dob column is of DATE datatype
    Code:
    $dob= $_POST['year'] . '-' . $_POST['month'] . '-' .$_POST['day'];
    $query=mysql_query("INSERT INTO user(dob) VALUES('$dob')",$con);
    The problem is, you're basically just adding number (text) to a DATE field. You need to turn them into an actual date. Do a search for PHP DATE and you'll see what I mean.

  • Users who have thanked iswd1 for this post:

    Saima Nazir (04-14-2012)

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post

    Yeah I GOT it...
    $dob1= $_POST['year'] . '-' . $_POST['month'] . '-' .$_POST['day'];
    $time = strtotime( $dob1 );
    $dob = date( 'y-m-d', $time );


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •