Heya all, first of all I apologise for asking this question about dates. I have searched on the subject - but for whatever reason cannot get my head around the date formatting done in PHP/MySQL.

I'm hoping someone will take pity on me and answer 🙁

If I have a date in MySQL table, it's formatted as YYYY-MM-DD ...

I would like to:

  1. Extract from the DB and display the date in my PHP page as DD/MM/YY

  2. Add a date in the format DD/MM/YY so that it succesfully inserts into the DB. (I would use a textbox to insert the date - is that the best way??)

  3. Show a list of upcoming events, ordered by how far away they are from the current date (ignoring dates that have passed). So I guess I'm asking for some sort of DateDiff function....

Please help me guys, I haven't got long left!

Cheers, LeeBoy
😃 :evilgrin: 🆒

    Step 1) reverse the date using [man]substr[/man]
    Step 2) turn the date into a timestamp using [man]strtotime[/man]
    Step 3) since the dates are now simple integers you can perform comparisons and mathematics on them easily.

      adding to Drawmack's suggestion you might want to use explode() function...

        I've found that all that date stuff is best done on the database level. I try to format dates as I get them out of MySQL or some other dbase.

        SELECT formatfunction(date,format) as mydate FROM bla bla bla

        echo $sql_row[mydate]....

          1) select date_format(datefield,'%d-%m-%Y') from table name

          2)
          if ur date field is called dob

          
          $dob=storeDateIST($dob);
          
          function storeDateIST($stringParam)
          	{
          		$tempVal=split("/",$stringParam);
          		$dt=$tempVal[0];
          		$mn=$tempVal[1];
          		$yr=$tempVal[2];
          		$finalVal=$yr."-".$mn."-".$dt;
          		return($finalVal);
          	}
          

          3) refer DATE_ADD / DATE_SUBTRACT in mysql.

          These are pretty much database oriented...

            Write a Reply...