Skip to content

Instantly share code, notes, and snippets.

@ivuorinen
Created January 22, 2019 13:47
Show Gist options
  • Save ivuorinen/f90c25fd85b042cd209ae41e03d988f3 to your computer and use it in GitHub Desktop.
Save ivuorinen/f90c25fd85b042cd209ae41e03d988f3 to your computer and use it in GitHub Desktop.
From 20190122-124559 to 2019-01-22 12:45:59 with preg_replace
<?php
// From 20190122-124559 to 2019-01-22 12:45:59
$patterns = '/(19|20)(\d{2})(\d{1,2})(\d{1,2})-(\d{1,2})(\d{1,2})(\d{1,2})/';
$replace = '\1\2-\3-\4 \5:\6:\7';
$date = preg_replace($patterns, $replace, $date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment