2

After trying Google and some other posts on here, I can not seem to find the answer.

I currently have dates stored in MYSQL as YYYY-mm-dd but for the ACF Date Picker in Wordpress it reads dates as yyyymmdd.

How can I convert the current format to the new format? All the other conversions seem to want it to have dashes but I was to take them away.

YasserKaddour
  • 880
  • 11
  • 23
Kyon147
  • 738
  • 2
  • 11
  • 28

4 Answers4

2
mysql> `SELECT col from tableA`
        -> '2008-06-13'
mysql> SELECT col+ 0 from tableA ;
        -> 20080613
Nayan Sharma
  • 1,823
  • 18
  • 19
0

Dates are stored in the database using an internal format. To convert them to a string, use the date_format() function:

select date_format(col, '%Y%m%d')

If the dates are stored as strings, then just use replace():

select replace(col, '-', '')

You can write views over the tables, if you don't want to do this every time you select from the tables.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You can use this

$originalDate = "2010-03-21";
$newDate = date("ymd", strtotime($originalDate));

Here is almost duplicate Convert date format yyyy-mm-dd => dd-mm-yyyy

Community
  • 1
  • 1
Shafi
  • 91
  • 8
0

Using all your advice I found the correct query to run.

UPDATE `wp_postmeta` 
SET meta_value = replace(meta_value, '-', '') 
WHERE `meta_key` = 'release_date'
Kyon147
  • 738
  • 2
  • 11
  • 28