How to create SQLite timestamp value in PHP

I want to create a timestamp in PHP and then save that value in SQLite.

Here is the code:

$ created_date = date ("YYYY-MM-DD NN: MM: SS", time ());

Here's what is stored in the database (which looks wrong): 11/21/0020 12:39:49 PM

How do I change the code to properly store the current date / time in SQLite

+4
source share
4 answers

Why not just update the SQLite query to use date('now') ? link

But in PHP you can use

 $created_date = date('Ymd H:i:s'); 
+7
source

I just implemented this for my own project.

My solution was to use the UTC time format officially specified for the Internet: RFC3339 . You can use any of the following PHP time format constants :

  • DATE_RFC3339
  • DATE_W3C
  • DATE_ATOM

Example:

 $sqlite_timestamp = date(DATE_RFC3339); echo "My SQLite timestamp = ".$sqlite_timestamp; 

The best part is the alphanumeric order corresponding to the date order, so you can use ORDER BY SQL expressions in date fields!

+2
source

How do you check what a stored value is? Also, what is the data type of the column in the database? You know that SQLite doesn't matter , so all values ​​are stored as strings or integers?

0
source
  $created_date = date('Ymd H:i:s'); echo $created_date ."<br />\n"; $created_date = date('l, F jS, Y - g:ia'); echo $created_date ."<br />\n"; $created_date = date('n/j/y H:i:s'); echo $created_date ."<br />\n"; $created_date = date('r'); // RFC 2822 formatted date echo $created_date ."<br />\n"; $created_date = date('c'); // ISO-8601 formatted date echo $created_date ."<br />\n"; 

The conclusion could be:

 2011-04-01 19:33:40 Friday, April 1st, 2011 - 7:33pm 4/1/11 19:33:40 Fri, 01 Apr 2011 19:33:40 +0200 2011-04-01T19:33:40+02:00 

Remember that the date () function depends on the default time zone set in the PHP configuration. You can always check it with echo date_default_timezone_get(); or set it date_default_timezone_set('TIMEZONE_IDENTIFIER'); where TIMEZONE_IDENTIFIER is one of the list of supported time zones .

0
source

Source: https://habr.com/ru/post/1346268/


All Articles