Can someone give me a quick and dirty way to split a datetime (28-1-2011 14:32:55) into just the date (28-1-2011) and the time ( 14:32 ) or even better (2:32 PM) using PHP. Using a mySQL database as well.
Cheers
Split date and time with Text to Column. In Excel, you also can use Text to Column to split the Date and Time column to columns. 1. Select the data range and click Data > Text to Columns, then in the popping dialog, check Delimited option.
If a cell contains a combined date and time, you can use the INT function to pull the time value into a separate column. Dates are stored as numbers in Excel, with the decimal portion representing the time. To calculate the time value, subtract the date integer value from the combined date and time. The remaining decimal portion is the time.
Use the INT Function to Split Date and Time Excel considers dates as integer numbers (starting from Jan 1, 1900) and times as fractions. So, we can separate the date part from the data using the INT function, then subtracting this result from the original data will return the time in Excel’s numeric format.
Then in the first cell of the Date column (except the header), type this formula =INT (A2) (A2 is the cell you need to split by), then drag the fill handle to the range needed to apply this formula. See screenshots: 5.
If you're using PHP > 5.2:
$myvalue = '28-1-2011 14:32:55';
$datetime = new DateTime($myvalue);
$date = $datetime->format('Y-m-d');
$time = $datetime->format('H:i:s');
Prior to PHP 5.2 mhitza gave a good answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With