homepage Welcome to WebmasterWorld Guest from 54.83.133.189
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Dates
PHP date
danno13




msg:1316429
 10:07 pm on Jul 2, 2002 (gmt 0)

i have a string that looks like this:
$date="2002-07-04";

how can i find out what weekday this date falls on?

 

jatar_k




msg:1316430
 10:25 pm on Jul 2, 2002 (gmt 0)

$date = getdate("2002-07-04");
$dayofweek = $date["weekday"];
echo $dayofweek;

<added>sorry

Welcome to WebmasterWorld danno13

jatar_k




msg:1316431
 10:34 pm on Jul 2, 2002 (gmt 0)

posted too quickly, that doesn't actually work but this does

$datestamp=mktime(0,0,0,4,7,2002);
$date = getdate($datestamp);
$dayofweek = $date["weekday"];
echo $dayofweek;

mktime [php.net] and getdate [php.net]

then you just have to get your date into the above format.

jatar_k




msg:1316432
 11:01 pm on Jul 2, 2002 (gmt 0)

OK, I've been messing around, this seems to work

$datestr = "2002-07-08";
$datearr = explode("-", $datestr);
$datestamp=mktime(0,0,0,$datearr[1],$datearr[2],$datearr[0]);
$date = getdate($datestamp);
$dayofweek = $date["weekday"];
echo $dayofweek;

danno13




msg:1316433
 11:06 pm on Jul 2, 2002 (gmt 0)

The following is the code i am using to test this. i am not getting the correct output. The lines that begin with"$datestamp=mktime" give me different results.

// Get the Formatted DATE for the invoice number from the orders table
$query = "SELECT DATE_FORMAT(invoiceDate, '0,0,0,%m,%d,%Y') FROM orders WHERE invoiceNumber=" . $invoiceNumber;
$resultDate = @mysql_query($query);

$rowDate = mysql_fetch_array($resultDate);

$formatedDate = $rowDate["DATE_FORMAT(invoiceDate, '0,0,0,%m,%d,%Y')"];
echo "<br>formatedDate = " . $formatedDate; //** this line prints - formatedDate = 0,0,0,07,15,2002

//$datestamp=mktime(0,0,0,07,15,2002); //** when i use this line i get the correct output , monday
$datestamp=mktime($formatedDate); //** when i use this line i get tuesday
echo "<br>datestamp= " . $datestamp;
$date = getdate($datestamp);
echo "<br>date = " . $date;
$dayofweek = $date["weekday"];
echo "<br>" . $dayofweek;

danno13




msg:1316434
 11:09 pm on Jul 2, 2002 (gmt 0)

thanks, jatar_k

that one works great.

jatar_k




msg:1316435
 11:11 pm on Jul 2, 2002 (gmt 0)

there also seems to be a mysql function

DAYOFWEEK [mysql.com]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved