If

$today = "11/13/08";

and I

echo "Timestamp using 'mktime' is ";
echo mktime($today);

and then I

echo "Timestamp using 'strtotime is ";
echo strtotime($today);

I get two different timestamps:

"Timestamp using 'mktime' is 1226592336
Timestamp using 'strtotime is 1226552400"

Why? What's the difference between mktime and strtotime? Which one is correct or more accurate?

Thanks!

Joe

===

I think I just answered my own question...

mktime($today) includes the hour,minute and seconds -- right??

If I

echo "Timestamp using 'mktime' is ";
echo mktime(0,0,0,$today);
echo "<br>";
echo "Timestamp using 'strtotime is ";
echo strtotime($today);

I get

"Timestamp using 'mktime' is 1226552400
Timestamp using 'strtotime is 1226552400"

Am I correct?

    when you call [man]mktime[/man] with missing arguments (like in your first example) then it will return the current time values. when you feed a just date (with no specific time) to [man]strtotime[/man] it will return the timestamp of 00:00:00 of that date. that is why you were getting 2 different results.

      Arrrrrgh...

      I thought I knew what I was doing...

      I still need help.

      I have a variable called $incidentDate and if I run a loop using mktime and strtotime, like:

      echo $incidentDate;
      echo "<br>";
      $incidentStamp=strtotime("$incidentDate");
      echo "The first timestamp is ",$incidentStamp,"<br>";
      echo "Another timestamp is ";
      echo mktime(0,0,0,$incidentDate);
      echo "<br>";

      I get:

      11/06/2008
      The first timestamp is 1225947600

      Another timestamp is 1226552400

      11/05/2008
      The first timestamp is 1225861200

      Another timestamp is 1226552400

      10/17/2008
      The first timestamp is 1224216000

      Another timestamp is 1223870400

      Why do I get 1226552400 for 3 different dates??

        what exactly are you trying to do here? are these dates stored in a database? are you simply trying to reformat them for display? more info please.

          devinemke;10892825 wrote:

          what exactly are you trying to do here? are these dates stored in a database? are you simply trying to reformat them for display? more info please.

          Yes, $incidentDate is stored in a database and it is the date that a server went down for maintenance, etc. I am trying to arrange the maintenance dates in chronological order using the timestamp but I want to make sure I am calculating the timestamp correctly.

          Does that make more sense?

            SELECT * FROM table ORDER BY incidentDate
            

            if you want to show the newest ones first:

            SELECT * FROM table ORDER BY incidentDate DESC
            
              devinemke;10892827 wrote:
              SELECT * FROM table ORDER BY incidentDate
              

              if you want to show the newest ones first:

              SELECT * FROM table ORDER BY incidentDate DESC
              

              Will it still work if the incidentDates are stored as text ("11/05/08," "10/25/08," etc.)?

                devinemke,

                I am using mySQL. I had been storing the dates as strings but now store them as dates (YYYY-MM-DD) as you suggested.

                When I am writing my php page, how do I then format the mySQL date (YYYY-MM-DD) to read m/d/y or as F j,Y ?

                (BTW, my $incidentDate(s) are in a loop)

                Thanks!

                  Write a Reply...