SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: {Problem} How to display date?
-
Feb 7, 2007, 12:02 #1
- Join Date
- Mar 2005
- Location
- South Africa
- Posts
- 202
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
{Problem} How to display date?
Im fairly new to PHP, but im pretty certain this is probably an easy problem. If it is then I apologise in Advance.
I have a date saved in a database in the 2007-02-07 Format
What I want to do is retrieve this from the database, but somehow break it up so that each part of the date becomes its own single variable.
For example...
$Year = "2007";
$Month = "02";
$Day = "07";
I hope I have made this clear. I would really appreciate some help.
-
Feb 7, 2007, 12:09 #2
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$date = '2007-02-07';
list($year, $month, $day) = explode('-', $date);
-
Feb 7, 2007, 12:12 #3
- Join Date
- May 2006
- Location
- Austin
- Posts
- 401
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
There are a few ways to do it.
The easiest that I can see is to split it into an array and use it however you need. This method would work best as long as it is always in this format.
PHP Code:$date = date_from_mysql_query;
$date = split('-',$date);
$year = $date[0];
$month = $date[1];
$day = $date[2];
Merchant Equipment Store - Merchant Services, POS, Equipment, and supplies.
Merchant Account Blog | Ecommerce Blog
-
Feb 7, 2007, 12:33 #4
- Join Date
- Mar 2005
- Location
- South Africa
- Posts
- 202
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks a milllion!! I will try those out.
-
Feb 7, 2007, 12:59 #5
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
split() and explode() are the same thing, in case you wonder.
-
Feb 8, 2007, 05:55 #6
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
not really, in case you care
PHP Code:print_r(split('.', "aa.bb.cc"));
print_r(explode('.', "aa.bb.cc"));
-
Feb 8, 2007, 06:03 #7
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Interesting!
-
Feb 8, 2007, 06:41 #8
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Fair enough.
These are the same then:
PHP Code:print_r(split('[.]', "aa.bb.cc"));
print_r(explode('.', "aa.bb.cc"));
-
Feb 8, 2007, 07:03 #9
Bookmarks