Re: [PHP] Date



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




Relevant Pages

  • Re: different results of query from different workstations
    ... The query converts a txt-field into a date format with the following ... General Date will have variable appearance depending on the computer's ... if your intention is to find all values more recent than 26 hours ago. ...
    (microsoft.public.access.queries)
  • Re: Getting entries from an SQL database with datetime parameter
    ... format is what you want. ... funtion to convert date string into date time accordig to your needs. ... your database, you will run into troubles comparing date to string. ... > hard coded a query to populate the datagrid, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DateTime field showing unwanted Time
    ... The time portion is 12:17:04 AM regardless of what table or database I open. ... If I run a query on a date field and convert it to a double format, ... the system automatically changes my ...
    (microsoft.public.access.setupconfig)
  • VBScript format database query to HTML
    ... I'm trying to write a script that will query a database, format the ... results into an html table, ...
    (microsoft.public.scripting.vbscript)
  • Re: Make Table Query
    ... I have 300 users of the database; however, 10 of the users need to enter the ... Delete Query for "temp" Table. ... If you want to control the format, ...
    (microsoft.public.access.queries)