Jump to content

Convert Date


sseeley

Recommended Posts

<?php
$date = 'dd/mm/yyyy';  //original string

$piece = explode('/',$date);  //array created by explode, containign different peices of the date...

$date2 = $piece[2].$piece[1].$piece[0];

echo $data2; //returns yyyymmdd

print_r($piece);

/*
array(
[0] =  'dd'.
[1] = 'mm'
[2] = 'yyyy'
)
*/

 

this relies on the input date always being input at the same format....

Link to comment
https://forums.phpfreaks.com/topic/139131-convert-date/#findComment-727678
Share on other sites

<?php
$date = 'dd/mm/yyyy';

$data = explode('/',$date);

$date2 = $data[2].$data[1].$data[0];

echo $data2; //returns yyyymmdd

this still wouldn't work because of leading zeros but your example can also be write as

echo str_replace("/",""$date);

 

Scott.

 

 

Link to comment
https://forums.phpfreaks.com/topic/139131-convert-date/#findComment-727682
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.