News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

PHP question regarding the date function.

Started by MoreBloodWine, February 10, 2015, 07:05:12 AM

Previous topic - Next topic

MoreBloodWine

I got something I'm working on and I wanted to add a "Week of: " line to it... it would run sunday to saturday so like for the current week. The output would basically look like this.

Week of: 2/8/15 - 2/14/15

Then for the next week it would be...

Week of: 2/15/15 - 2/21/15

So on n so forth.

Can someone please write out the code to do this for me please ?

Ty.
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Shambles

I'm no php programmer, but looking at the functions manual, this might work


<?php
// Constant value indicating one days worth of seconds
$oneDay 60 60 24 ;

// Get the time right now
$timeNow time() ;

// Find out the day of the week (0 = Sunday)
$dayOfWeek date("w"$timeNow) ;

// Calculate the date last Sunday
$lastSundayTime $timeNow - ( $dayOfWeek $oneDay ) ;

// Calculate the date next Saturday
$nextSaturdayTime $lastSundayTime $oneDay 

// Format the output
$output =  date("m/d/y",$lastSundayTime) . ' - ' date("m/d/y"$nextSaturdayTime) ;

// Display it
echo $output ;
?>

MoreBloodWine

Quote from: Shambles on February 10, 2015, 08:32:19 AM
I'm no php programmer, but looking at the functions manual, this might work


<?php
// Constant value indicating one days worth of seconds
$oneDay 60 60 24 ;

// Get the time right now
$timeNow time() ;

// Find out the day of the week (0 = Sunday)
$dayOfWeek date("w"$timeNow) ;

// Calculate the date last Sunday
$lastSundayTime $timeNow - ( $dayOfWeek $oneDay ) ;

// Calculate the date next Saturday
$nextSaturdayTime $lastSundayTime $oneDay 

// Format the output
$output =  date("m/d/y",$lastSundayTime) . ' - ' date("m/d/y"$nextSaturdayTime) ;

// Display it
echo $output ;
?>

That appears to have done the trick, Ty ;-)
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Advertisement: