View Single Post

  #3 (permalink)  
Old 03-12-2008
Alred Wallace
 
Posts: n/a
Default Re: retrieve the day of the week


"Kram Techie" <kramTechie@NOSPAM.ntlworld.com> a écrit dans le message de
news: 9PPBj.10809$qW6.8607@newsfe6-win.ntli.net...
> Hi
>
> i am trying to find a way to retrieve the day of the week from a mysql
> date.
> example 11 Mar 2008 22:32:06
> should equate to Tue, or Tuesday
>
> Googled but no Joy. many online examples but i need a hint or some source
> to work with.
>
> Mark
>
>



hi Mark,
first the timestamp is the best way to find day of the week. A timestamp
look like : 3215649870354 (secondes).

I don't know how are stored your data. Let's imagine the worst: in a
string!!
and the month are stored like:jan, mar,feb...
and not like 1 (jan), 2 (feb)...
we will be forced to make an array.
Let's begin the script:

<?
///////////////// input date:
$date = "11 Mar 2008 22:32:06";

///////////// array retrivinbg number of months:
$Months = Array(
"Jan" => 1,
"Feb" => 2,
"Mar" => 3,
"Apr" => 4,
"May" => 5,
"Jun" => 6,
"Jul" => 7,
"Aug" => 8,
"Sep" => 9,
"Oct" => 10,
"Nov" => 11,
"Dec" => 12
);


///////// let's transorm your date in timestamp:
/// let's mlake an array to retrive values of: day, month, year:
$dateArray = explode( " ",$date );
$day = $dateArray[0];
/////// tranform the month like "Mar" in a number (3)
$month = $Months[ $dateArray[1] ];
$year=$dateArray[2];
///// now, we own: $day, $month,$year in numeric format.

// creating timestamp: mktime(hour, minute,second,month,day,year);
/////// in this case the value is:1205193600
$dateTimeStamp = mktime( 1, 0 , 0 , $month , $day , $year );

//////// retreiving the name of the day (see "date function" doc in php
manual)
//// "l" is L lowercase
$TheNameOfTheDay = date( "l",$dateTimeStamp );

echo "date ini:".$date."<br />";
echo "<h1>".$TheNameOfTheDay."</h1>";
echo "timestamp:".$dateTimeStamp;
?>






Reply With Quote