XF 2.0 Convert database field YYYY-MM-DD to XF format

AndrewSimm

Well-known member
I don't fully understand how XF2 comes up with the date number. How would I convert a field formatted as YYYY-MM-DD to the XF2 format?
 
the long numbers are called a unix timestamp

to convert to something you can manipulate in MySQL, use the FROM_UNIXTIME function in your query

To go the other way, there is an equivalent UNIX_TIMESTAMP function - but be aware that translation between the two values is lossy in regards to timezone mapping (unixtime should generally be in GMT).

Alternatively, look at using a library like Carbon to make time format conversions and manipulation in PHP
 
Here you go:

PHP:
<?php

$string = '20171021';

$dateline = strtotime($string);

echo $dateline;

This website is really handy to convert unix timestamp to human readable date and vice versa.

https://www.epochconverter.com/

What I am trying to do is convert a column to unix timestamps from yyyy-mm-dd. Once I have it in the unix timestamps, I can use the xf function to read it.
 
Ok, it was easy to convert

SQL:
update table
set field = UNIX_TIMESTAMP(field)

Now, when I read the date it reads correctly
 
Back
Top Bottom