Advertisement
Guest User

Untitled

a guest
Jul 25th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Converting dates with PHP for DATETIME in SQL
  2. $new_date = date( "Y-m-d H:i:s", strtotime( $old_date ) );
  3.  
  4. $timestamp = '31/05/2001 12:22:56';
  5. $timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
  6. echo $timestamp->format('Y-m-d H:i:s');
  7.  
  8. $timestamp = '31/05/2001 12:22:56';
  9. $timestamp = date_create_from_format('d/m/Y H:i:s', $timestamp);
  10. echo date_format($timestamp, 'Y-m-d H:i:s');
  11.  
  12. function localToMysql($dateTime){
  13. $date_chunks = explode('/', $dateTime);
  14. $time_chunks = explode(' ', $date_chunks[2]);
  15. $final_format = $time_chunks[0] . "-" . $date_chunks[1] . "-" . $date_chunks[0] . " " . $time_chunks[1];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement