Currently I have a date in the format: 04/07/2014, (4/7/2014) I need to change this so that it is: 07/04/2014 so I can convert it to a time stamp using: $time1 = strtotime("dd/mm/yy"); I am doing this so I can compare multiple dates. How can I do this using php?
            Asked
            
        
        
            Active
            
        
            Viewed 38 times
        
    -2
            
            
        - 
                    Why don't you just do a `$time1 = strtotime("mm/dd/yy");` ? – arkascha Apr 07 '14 at 23:22
- 
                    If you just need to get a timestamp, use [date_create_from_format](http://www.php.net/manual/en/datetime.createfromformat.php) – Jonathan Kuhn Apr 07 '14 at 23:23
- 
                    Is 04/07/2014 in DD/MM/YYYY or MM/DD/YYYY? – Shahar Apr 07 '14 at 23:23
- 
                    Is "04/07/2014" a string or a `date`? – Shahar Apr 07 '14 at 23:25
- 
                    "04/07/14" is a string and in the format: MM/DD/YYYY – user3505931 Apr 07 '14 at 23:27
- 
                    I may be misunderstanding this command, @arkascha could I do $date= strtotime("mm/dd/yy"); (assuming $date is 04/07/14)? – user3505931 Apr 07 '14 at 23:29
1 Answers
0
            Here is simple function:
<?php
function format_date($dateToConvert) {
    return date('d/m/Y', strtotime($dateToConvert));
}
$date = "04/07/14";
echo format_date($date);
Output: 07/04/2014
 
    
    
        Black Sheep
        
- 6,604
- 7
- 30
- 51
- 
                    Thankyou, concise and well written, allowing for quick and efficient implementation. – user3505931 Apr 07 '14 at 23:37
- 
                    
- 
                    read this-> http://stackoverflow.com/questions/113829/how-to-convert-date-to-timestamp-in-php – Black Sheep Apr 07 '14 at 23:45
