Jump to content

FinalRevival

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Posts posted by FinalRevival

  1. Hi AndyB, Thank you for your reply.

    There is a form I get the dates from. The format I recieve the dates is MM-DD-YYYY. I had to change the format to YYYY-MM-DD so I could insert into mysql db.

    I solved this problem by using a PHP function, which is below.

    You see, MySQL versions didn't match so I had to look for other ways of changing date format.

    I believe there is other ways of doing this. You are still very welcome to share those solutions. I want to learn different ways of doing things.

    The way I solved this date format issue:

    [code]
    $fdate='06-31-2004';

    function changeDate ($inputDate) {
      $split = explode("-", $inputDate);
      $outputDate = "" . $split[2] . "-" . $split[1] . "-" . $split[0];
      Return $outputDate;
    }
    echo changeDate ($fdate);
    [/code]

    the result will be : 2004-06-31
  2. My first code was working fine. It is MySQL 5.x installed on my machine. I used STR_TO_DATE() then uploaded my files, found out that the server has the version 3.x.x which doesn't support the function I used. Spending 6 hours today I found SUBSTRING_INDEX() function and how to convert a date from MM-DD-YYYY to YYYY-MM-DD format.

    From the command line everything works fine. I've tested the function but couldn't use it with PHP. I wrote a code to test the function with PHP and I am stuck, I don't know what I am doing wrong. I copied the code below.

    If there is any other way that I could convert the date format, can you tell me about that? I appreciate any help. Thank you and here is the code used to test the function. Page doesn't give any error messages, nothing, just a blank white page is all it displayed.

    [code]
    mysql_connect($hostname,$username,$password);
    mysql_select_db($database) or die(mysql_error());

    #$fdate='12-31-2006';

    #echo $fdate;

    $query="SUBSTRING_INDEX('12-31-2006','-',-1)";

    $result = mysql_query($query);

    echo $result;
    [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.