CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2010
    Posts
    111

    Unhappy insert date value into sql using php?

    i want to store date in many fields of sql server 2000, the date field having the datatype datetime and i pass the value to the date field like below

    Code:
     $now=date("m/d/Y h:i:s A");
     
                mssql_bind($stmt,"@s_date", $var1,SQLINT4);


    first variable got insert the now date successfully but other dates values didnt insert now value it store like 1/2/1900 12:00:00 AM


    why it behave like this can any one suggest me answer to this


    thanks
    sona

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: insert date value into sql using php?

    Date formatting for SQL and SQL derivatives is "YYYY/MM/DD HH:MM:SS" and not as you have it. Note that the hour is 24, not 12.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Mar 2010
    Posts
    111

    Re: insert date value into sql using php?

    hi thanks for ur reply

    i want this format to be stored in database "m/d/Y h:i:s A" ?

    how to i achieve this using php and store it in database.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: insert date value into sql using php?

    The only way to do that is to make the column of varchar type. But, that's a very, very poor implementation because then you lose the date/time object.

    Use the proper format and just display the formatted date with PHP. Why do you think that PHP has such an extensive date/time function set?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Mar 2010
    Posts
    111

    Re: insert date value into sql using php?

    hi how to bind the post value of date using php for sql

    can u give sample code ..

    Code:
    $now=date("Y/M/D H:I:S");
    but it produce like this Jul 5 1905 12:00AM

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: insert date value into sql using php?

    Please start trying to do some of your own work...http://ar2.php.net/manual/en/function.date.php
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Mar 2010
    Posts
    111

    Re: insert date value into sql using php?

    hi

    what is datatype for bind the datetime into msssql. i used sqlint4 but it is not correctly bind value.

    i know about the date functions.

    Code:
     
    $now="1/2/2003";
     
                mssql_bind($stmt,"@s_date", $now,SQLINT4);
    @s_date datetime

    i bind now variable to datefield but in database didnt store this value instead of it store the default time

    1/2/1900 12:00:00 AM

    the problem is the datatype i passed or data value which is i used ? can u guide me

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: insert date value into sql using php?

    That's because binding requires that the variable be of the same time. Since PHP does not have a datetime type variable, you need to use a query, not a bind.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured