|
-
Aug 3rd, 2007, 12:20 PM
#1
Thread Starter
Lively Member
retrieve day,month and year from date
hi,
i want do retrieve a dau,month,year from a date that i give
how can i do that?
thanks for your help
-
Aug 3rd, 2007, 12:30 PM
#2
Re: retrieve day,month and year from date
depends on how it is formated. give us an example
My usual boring signature: Something
-
Aug 3rd, 2007, 12:36 PM
#3
Re: retrieve day,month and year from date
Use regular expressions or strtotime()
-
Aug 3rd, 2007, 12:51 PM
#4
Thread Starter
Lively Member
Re: retrieve day,month and year from date
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
-
Aug 3rd, 2007, 12:54 PM
#5
Re: retrieve day,month and year from date
date()
PHP Code:
echo date("j-n-Y");
j - Month Number (without prefixed 0 ) [1-12]
n - day of month (without prefixed 0 ) [1-31]
Y - full year [1999]
check this out for more info: http://us2.php.net/date
My usual boring signature: Something
-
Aug 3rd, 2007, 01:27 PM
#6
Re: retrieve day,month and year from 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.
-
Aug 3rd, 2007, 04:44 PM
#7
Re: retrieve day,month and year from date
he said he doesn't know how to format it, so i was showing him how to
My usual boring signature: Something
-
Aug 4th, 2007, 05:07 AM
#8
Re: retrieve day,month and year from date
 Originally Posted by dclamp
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.
-
Aug 4th, 2007, 08:24 AM
#9
Hyperactive Member
Re: retrieve day,month and year from date
Such as the following:
PHP Code:
echo date("j-n-Y". strtotime(/*DATE VAR HERE*/));
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Aug 4th, 2007, 08:30 AM
#10
Re: retrieve day,month and year from date
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.
-
Aug 20th, 2007, 08:38 AM
#11
Addicted Member
Re: retrieve day,month and year from date
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]");
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|