How do I get the unix timestamp converted from for example, 20.10.02??

Also, do i have to specify the time to convert it into a timestamp??

    strtotime() was way to much work.

    I think I could get this to work with mktime().

    However, I tried to write this function like this:
    $test = mktime ('d.m.y', 30.10.02);

    That did not work. When I tried to rewrite it like this:
    $test = mktime ('d.m.y', 30.10-02);

    This worked. Anyone who know why I couldn't use dd.mm.yy in the code above???

      Its because you didn't get the syntax of mktime right!

      Syntax is
      -> mktime(hour, minute, second, month, day, year)
      If you leave away one param for example
      -> mktime(1,2,0,0,0)
      mktime gets the not present one from local time.

      Lets say local time is 09.52pm at 31 of october 2002

      mktime(1,2,0,0,0) is the same as

      mktime(1,2,0,0,0,2002 .

      Knowing that we look back at your code. So if you try to get
      mktime('d.m.y',30.10-02) mktime starts parsing at the left. Lets see. There is 'd.m.y' which is 0 seing it as an integer which is definitly the way mktime does (see documentation). Next is 30.10-02. 30.10 is same as 30,10 ok. OH! We have to sutract 2 (-2) so second param is (30,1 - 2) 28.1!
      So in your code you told mktime to make a time which is (looking at my given local time above)

      hour 28.1! which is 0 cause hours above 23 aren't that good
      minute 0!
      rest is coming form local. I think didn't want it that way!

      All together you told mktime to make a time :-) which is at 0.00am at the date given by local time.

      For your example it would be
      mktime(0,0,0,10,30,02). Now it must be clear why mktime(30.10.02) didn't worked cause an integer like 3.4.3 wasn't seen before :-)

      Hope that helps.

      buzz

        Thanks a lot Buzz.

        With your help I did the following:

        <?
        $wholedate = '23.10.02';

        $date_array = explode('.', $wholedate);

        $test = mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2]);

        echo $test; //the timestamp I can store in MySQL (BINGO:-)

        echo '<br>';

        echo date('d.m.y', $test); //Check if timestamp returns wanted date format
        ?>

        With this code I can post the date from my page and translate it to unix timestamp.

        However, there should be developed a function in php that did this in one line. For example datetounix('date format', 'timestamp').

        Once again, thank you Buzz.

          Write a Reply...