Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Lee Laing
Added: Apr 5, 2018 6:53 AM
Views: 17
Tags: no tags
Insert Date and Time into Database Example from video https://www.youtube.com/watch?v=SceCb09fwSo
  1. <?php
  2.  
  3. include_once 'include/dbconnect.php';
  4.  
  5. // Check connection
  6. if ($conn->connect_error) {
  7.     die("Connection failed: " . $conn->connect_error);
  8.  
  9. //echo "Connected successfully"
  10. }
  11.  
  12. //$time = strftime("%Y. %B %d. %A. %X %Z");
  13.  
  14. // [created_at] => Sun Mar 23 06:39:16 +0000 2008
  15.  
  16.         $raw = "Sun Mar 23 06:39:16 +0000 2008";
  17.  
  18.         $xplod = explode(' ', $raw);
  19.  
  20.         print_r($xplod);
  21.  
  22.         $string = "$xplod[5]-$xplod[1]-$xplod[2] $xplod[3]";
  23.  
  24.         echo "<br />$string";
  25.  
  26.         $date = date("Y-m-d H:i:s", strtotime($string));
  27.  
  28.         echo "<br />$date";
  29.  
  30.  
  31.         if(msql_query("INSERT INTO tbl_sample VALUES('$date')"))
  32.                 echo "Inserted successfully!";
  33.         else
  34.                 echo "Failed .. please try again!";
  35. //END: [created_at] => Sun Mar 23 06:39:16 +0000 2008