Re: [PHP] Date
- From: mrsquash2@xxxxxxxxx ("Dan Shirah")
- Date: Wed, 20 Jun 2007 10:06:34 -0400
If you are pulling $start_date from a database, depending on the format you
could use something like the following:
Assuming the data is 20070215.
Connect and query your database, get the result and assign it to a variable.
$start_date = $my_result_row['start_date'];
$start_year = substr($start_date, 0, 4);
$start_month = substr($start_date, 4, 2);
$start_day = substr($start_date, 6, 2);
Now you will have variables for the entire date, the year, the month and the
day to play around with however you want.
On 6/20/07, Fredrik Thunberg <thunis@xxxxxxxxxxxxxxxxxxx> wrote:
Ron Piggott skrev:
> How do I break $start_date into 3 variables --- 4 digit year, 2 digit
> month and 2 digit day?
>
> $start_year = ;
> $start_month = ;
> $start_day = ;
>
>
Of course depending on what $start_date looks like, but this should work
most of the time:
$timestamp = strtotime( $start_date );
$start_year = date( "Y", $timestamp );
$start_month = date( "m", $timestamp );
$start_day = date( "d", $timestamp );
/T
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
- References:
- Re: [PHP] Date
- From: Fredrik Thunberg
- Re: [PHP] Date
- Prev by Date: Re: [PHP] Date
- Next by Date: Re: Hey, where can i get your chat script?
- Previous by thread: Re: [PHP] Date
- Next by thread: RE: [PHP] Date
- Index(es):
Relevant Pages
|