SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: help me..

  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help me..

    i'm newbie in php language, so i want to know that how to convert the date from this format (dd/mm/yy) to the (mm/dd/yy). i'm using sql server that store the date data (mm/dd/yyyy). There was an error if i insert 13/1/04(dd/mm/yy) from the form as an instance.

  2. #2
    SitePoint Guru dragonhawk's Avatar
    Join Date
    Apr 2002
    Location
    Melbourne
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if this would be the best way to do it, but you could use the explode() function

    PHP Code:
    $explode=explode("/",$datevalue);
    $day=$explode[0];
    $month=$explode[1];
    $year=$explode[2];

    $newdateformat="$month/$day/$year"
    Personally though, I would go with the timestamp value and store as an integer instead of the date value

  3. #3
    SitePoint Zealot Ap0s7le's Avatar
    Join Date
    Jul 2003
    Location
    Lousiville, KY
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to convert all the current dates in the database to the new format, or simply wanting the form to insert them in the new format?

  4. #4
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simply wanting the form to insert them in the new format. Moreover, the error displayd ([Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.)

    .
    .
    .
    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO desk (date_no, price, code) VALUES (%s, %s, %s)",
    GetSQLValueString($HTTP_POST_VARS['date_no'], "date"),
    GetSQLValueString($HTTP_POST_VARS['price1'], "text"),
    GetSQLValueString($HTTP_POST_VARS['code1'], "text"));
    .
    .
    .

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks dragon hawk. i made it.


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
  •