if i have a date and i want to extract the year, the month, etc in PHP5, how should i proceed?
if i do
$y = date('Y',$sale->end);
it doesn't work...
date_default_timezone_set('UTC'); echo "<strong>Display current date dd/mm/yyyy format </strong>". "<br />"; echo date("d/m/Y"). "<br />"; echo "<strong>Display current date mm/dd/yyyy format</strong> "."<br />"; echo date("m/d/Y")."<br />"; echo "<strong>Display current date mm-dd-yyyy format </strong>".
Specifies the format of the outputted date string. The following characters can be used: d - The day of the month (from 01 to 31)
Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );
Definition and Usage. The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
If $sale->end
is a valid datestamp, pass it through strtotime()
like so:
$y = date('Y', strtotime($sale->end));
As jnpcl indicated, if $sale->end
holds a valid datestamp you can do the following:
list($year,$month,$day,$hour,$minute,$second)=explode('-',date('Y-m-d-h-i-s',strtotime($sale->end)));
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