hi,
i want do retrieve a dau,month,year from a date that i give
how can i do that?
thanks for your help
Printable View
hi,
i want do retrieve a dau,month,year from a date that i give
how can i do that?
thanks for your help
depends on how it is formated. give us an example
Use regular expressions or strtotime()
hi,
i have a problem in format of the data to.
in my local server they store in this format:2002-2-12
but in the real server in store in this format:2-12-2002
so how can i retrieve from a format that i want?
thanks for your help
date()
j - Month Number (without prefixed 0 ) [1-12]PHP Code:echo date("j-n-Y");
n - day of month (without prefixed 0 ) [1-31]
Y - full year [1999]
check this out for more info: http://us2.php.net/date
Dclamp, If the date is stored as a string. The date() function is of no use. You will have no choice by to use a regular expression to extract the individual components of the date and pass them to the mktime() function to create time stamp.
You can then pass it to the date function or the strftime function to get it in the format you need.
he said he doesn't know how to format it, so i was showing him how to
The date function only formats timestamps not strings. You need to get the string into a timestamp before you can use the date() function on it.Quote:
Originally Posted by dclamp
Such as the following:
PHP Code:echo date("j-n-Y". strtotime(/*DATE VAR HERE*/));
If you are using PHP version 5.2.0+ you can use the DateTime class to manipulate timestamps.
Note that while the manual says version 5.1.0, it is not in fact enabled by default until 5.2.0.
I am not sure if you actually need it but if the Date is "2007-08-20" (YYYY-MM-DD). Then
PHP Code:<?PHP
$Date = "2007-08-20";
$Explode_Date = explode("-", $Date);
echo("Year: $Explode_Date[0]");
echo("Month: $Explode_Date[1]");
echo("Date: $Explode_Date[2]");
?>