$text = "2011 16 10 12:00AM";
$marker = strrpos( $text, ' ' ) ; 
$last = substr( $text, 0, $marker ) ;
echo $last.'<br>';
echo strtotime($last); 

Need to convert the above date (in that format) into a unix timestamp. Doesn't seem to be working.

Thanks

    one way:

    $text = "2011 16 10 12:00AM";
    $bang=explode(' ',$text);
    echo   mktime(0,0,0,$bang[2],$bang[1],$bang[0]);
    
      theknight;10987751 wrote:
      $text = "2011 16 10 12:00AM";
      [/quote]
      Do note that as soon as AM disappears from 12, the time should instead be 00, so if you want to actually use your input data, rather than presupplying a time of 0, 0, 0, you'd need to correct for this
      
      Also, I don't believe (but I may be wrong) that there is any date format using "YYYY DD MM" format. Americans do put day before month, but they do so using "MM DD YYYY" format. Thus, looking at the string is highly confusing, and as soon as you don't have a day > 12, noone will assume that you have this input format.
      
      If you correct your format to match either of the above and also use - instead of whitespaces, strtotime will work. You will not even need to substr anything, since strotime('2011-10-16 12:00AM') is the same as strtotime('2011-10-16');

        My apologies for adding a unix timestamp question onto this thread, but what is the unix letter to use for display the full text of a day (i.e. Monday, Tuesday)?

          NiallThistle;10987803 wrote:

          what is the unix letter to use for display the full text of a day (i.e. Monday, Tuesday)?

          While your question makes no sense (what is a "unix letter" ... ?!), I'm guessing that you're asking what character to use in the format string for [man]date/man? If that's true, then read the (friendly) manual.

          EDIT: Also, why apologize for hijacking a thread and then continue on doing just that? Just start your own thread in the future. 😉

            dagon;10987760 wrote:

            one way:

            $text = "2011 16 10 12:00AM";
            $bang=explode(' ',$text);
            echo   mktime(0,0,0,$bang[2],$bang[1],$bang[0]);
            

            This worked but the outputted timestamps are not accurate.

            /**
             *
             * date function
             */
             //todays date 15/09/2011
            $date = date("Y m d");
            echo $date.'<br>';
            echo mktime($date).'<br>';
            
            
            //outputs 1323285831
            
            $text = "2011 09 15 12:00AM"; 
            $bang=explode(' ',$text);
            print_r($bang);
            echo '<br>';
            echo   mktime(0,0,0,$bang[2],$bang[1],$bang[0]);
            
            //outputs 1331251200
            

            Time stamps are different. I think the first timestamp seems to be before the second timestamp, when the first timestamp is todays date and therefore should be more accurate.

            After using a timestamp to date converter:

            http://www.epochconverter.com/

            Turns out timestamps are not similar to the dates. When converted from the outputted timestamp.

              johanafm;10987796 wrote:

              Do note that as soon as AM disappears from 12, the time should instead be 00, so if you want to actually use your input data, rather than presupplying a time of 0, 0, 0, you'd need to correct for this

              Also, I don't believe (but I may be wrong) that there is any date format using "YYYY DD MM" format. Americans do put day before month, but they do so using "MM DD YYYY" format. Thus, looking at the string is highly confusing, and as soon as you don't have a day > 12, noone will assume that you have this input format.

              Its the format outputted by MSSQL

              If you correct your format to match either of the above and also use - instead of whitespaces, strtotime will work. You will not even need to substr anything, since strotime('2011-10-16 12:00AM') is the same as strtotime('2011-10-16');

              The actual time stamp is not similar when I tried this.

                Resolved it, formatting issue.

                All dates have to be formatted this way:

                month day Year

                Otherwise it does not produce the correct timestamp

                  theknight;10987808 wrote:

                  Resolved it, formatting issue.
                  All dates have to be formatted this way:
                  month day Year
                  Otherwise it does not produce the correct timestamp

                  Wrong! All dates have to be formatted in any of the ways described acceptable by the manual. There is a link to the page of acceptable formats on the strtotime page.

                  theknight;10987807 wrote:

                  Its the format outputted by MSSQL

                  Don't they have the DATE_FORMAT function?

                  theknight;10987807 wrote:

                  The actual time stamp is not similar when I tried this.

                  Similar to what? PHP's time functions do not randomly return some integer > 0. What use would a time function be if it produced varying times for the same given input?

                  echo strtotime('2011-10-16 12:00AM') . '<br/>';
                  echo strtotime('2011-10-16') . '<br/>';
                  echo strtotime('10/16/2011 12:00AM') . '<br/>';
                  echo mktime(0, 0, 0, 10, 16, 2011) . '<br/>';
                  

                  output

                  1318716000
                  1318716000
                  1318716000
                  1318716000
                  

                  That is, they are all not just similar, but identical.

                  theknight;10987806 wrote:

                  This worked but the outputted timestamps are not accurate.

                  Yes, they are.

                  theknight;10987806 wrote:
                  $date = date("Y m d");
                  echo mktime($date).'<br>';
                  
                  $text = "2011 09 15 12:00AM"; 
                  $bang=explode(' ',$text);
                  echo   mktime(0,0,0,$bang[2],$bang[1],$bang[0]);
                  
                  //outputs 1331251200
                  

                  Time stamps are different.

                  Of course they are. You don't create them using the same input. The first one has input 2011, which I wouldn't know where to being to guess how it's treated for hour value, since hour has range 0-23, which makes this

                  echo mktime(2011);
                  

                  very weird indeed.

                  theknight;10987806 wrote:

                  when the first timestamp is todays date and therefore should be more accurate.

                  More accurate than what? They are all equally accurate.

                  theknight;10987806 wrote:

                  Turns out timestamps are not similar to the dates.

                  Dates specify a specific day while a timestamp specifies a specific time. If you convert a date to a timestamp, you are (by convention) taking the midnight time, 00:00:00, of that day and turning that into a timestamp.

                  As for your little mktime example, you do have to actually follow the format of the input parameters of the functions you use

                  /*
                  # todays date 15/09/2011
                  	$date = date("Y m d");
                  	echo $date.'<br>';
                  	echo mktime($date).'<br>';
                  */
                  echo (int) '2011 09 15';
                  echo '<br/>';
                  echo mktime('2011 09 15') . '<br/>';
                  echo mktime(2011);
                  

                  Output (at 2011-09-15 15:16:31)

                  1316092591
                  1316092591
                  

                  which is, once again, entirely accurate and produces identical output to equivalent input parameters.

                    johanafm;10987815 wrote:

                    Wrong! All dates have to be formatted in any of the ways described acceptable by the manual. There is a link to the page of acceptable formats on the strtotime page.

                    Don't they have the DATE_FORMAT function?

                    Yeah its called CONVERT

                    $this->db->select('CONVERT(VARCHAR(11), date.EndDate, 100) as newEndDate');

                    For some reason it is not working.

                      You'd need a varchar(19) for that to fit. And if you want the standard date format, it's 120.

                        johanafm;10987817 wrote:

                        You'd need a varchar(19) for that to fit. And if you want the standard date format, it's 120.

                        Used 101 as date format

                        That works, output is odd:

                        Here is my php

                        $text = $row['newEndDate'];
                                            echo $text.'<br>'; 
                                            $timestamp = mktime($text);
                                            echo $timestamp;
                        
                        Output:
                        
                        12/16/2011
                        
                        1316087900
                        ([B]Thu, 15 Sep 2011[/B])
                        
                        12/16/2011
                        
                        1316087900
                        ([B]Thu, 15 Sep 2011[/B])
                        
                        1316044700
                        [B]Wed, 14 Sep 2011 23:58:20 GMT[/B]
                        

                        Bolded are timestamps converted to dates.

                        Thanks again.

                          Got it working, had to add 0,0,0 to mktime

                            Write a Reply...