Dear Brothers,
I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As
MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used the MYSQL Tables DateTime Type as Text.
Time-formet 1. 04:02:27 16/01/2009
Time-formet 2. 16/01/2009 13:53:19
Time-formet 3. 00901E+13
Time-formet 4. Wed Jan 14 00:09:09 BDT 2009
I need to convert/change each date-time into j-M-y(14-Jan-09) H:i:s(00:00:00) format.
For converting Time-formet 1. I have used the following PHP code.
I have spent much time to change these time formats into my desired format (14-Jan-09 00:00:00).Pleas e give me an efficient
solution for these (4 types) date time types.
I am waiting for your valuable help.
Kind Regards,
A H MUrad
I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As
MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used the MYSQL Tables DateTime Type as Text.
Time-formet 1. 04:02:27 16/01/2009
Time-formet 2. 16/01/2009 13:53:19
Time-formet 3. 00901E+13
Time-formet 4. Wed Jan 14 00:09:09 BDT 2009
I need to convert/change each date-time into j-M-y(14-Jan-09) H:i:s(00:00:00) format.
For converting Time-formet 1. I have used the following PHP code.
Code:
$vocc_dt="04:02:27 16/01/2009";
$vrec_dt="08:02:27 16/01/2009";
$occ_dt=strtotime($vocc_dt);
$rec_dt=strtotime($vrec_dt);
$for_vocc_d = date('j-M-y',$occ_dt);
$for_vocc_t = date('H:i:s',$occ_dt);
$for_vrec_d = date('j-M-y',$rec_dt);
$for_vrec_t = date('H:i:s',$rec_dt);
echo "Occurance Date Time: $for_vocc_d $for_vocc_t<br>";
echo "Recovery Date Time : $for_vocc_d $for_vocc_t<br>";
//This script gives invalid date time like 1-Jan-70 00:00:00 but if i use like below..
$vocc_dt="04:02:27 1/16/2009";
$vrec_dt="08:02:27 1/16/2009";
//it gives accurate output....
//for time difference I have used the following php code:
function date_diff($d1, $d2){
$d1 = (is_string($d1) ? strtotime($d1) : $d1);
$d2 = (is_string($d2) ? strtotime($d2) : $d2);
$diff_secs = abs($d1 - $d2);
$base_year = min(date("Y", $d1), date("Y", $d2));
$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
return $diff_secs;
}
$vduration = date_diff("$vocc_dt", "$vrec_dt");
$unith =3600;
$unitm =60;
$hh = intval($vduration / $unith);
$ss_remaining = ($vduration - ($hh * 3600));
$mm = intval($ss_remaining / $unitm);
$ss = ($ss_remaining - ($mm * 60));
//It also gives the accurate duration.
solution for these (4 types) date time types.
I am waiting for your valuable help.
Kind Regards,
A H MUrad
Comment