views:

43

answers:

4

i want to set a variable to a particular date like this in php..how to write this function in php? jsmyStartDate = new Date('April 1, '+curYear+' 1:59:59');

+1  A: 

take a look at date in the php manual, you're almost on the right way (just replace the R with eO ;) ).

it looks like you want the date to be in RFC2822-format, in this case you could also simply use date("r").

oezi
Nearly there, except for the written out Time zone identifier. That seems to be `date("r e");`
Pekka
+2  A: 

do you mean

<?php

$today = date("D M j Y  g:i:s e O");

echo $today;

// Thu Oct 14 2010 10:56:17 Europe/London +0100

or why not just

date('r');

Ross
@ross thanks. i want to extract year from $today,something like this $year=date($today); is this correct?
mayuri
`$today = date("D M j Y g:i:s e O");``$year=date("Y", strtotime($today));``echo $year; //2010 -` gets the year from the original date.
Ross
i want to set a variable to a particular date like this in php..js: myStartDate = new Date('April 1, '+curYear+' 1:59:59');how to write this function in php?
mayuri
A: 

Why is this voted down? Its simple but still...

use date("D M j Y g:i:s \G\M\TO"); (larg o at the end)

Hannes
A: 

Found this on the php.net site - http://php.net/manual/en/function.date.php right at the bottom

<?php

function zonedate($layout, $countryzone)
{
    if ( $countryzone >> 0 )
    {
        $zone = 3600 * $countryzone;
    }
    else
    {
        $zone = 0;
    }

    $date = gmdate($layout, time() + $zone);
    return $date;
}

$layout = "D M j Y g:i:s e O";
$countryzone = 5.5;

echo zonedate($layout, $countryzone);

?>

Try something like this?

etbal
hehe @oezi Beat me to it! Nice one :)
etbal