Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to Calendar Events THis Week 1

Status
Not open for further replies.

clivehenderson

IS-IT--Management
Nov 2, 2002
66
GB
Hi

I’d like to be able to convert a date retrieved in a recordset to a date this week

e.g a date last month might be a Thursday and I’d like to convert it to the thursday date this week. Does anyone know a clever/simply way to do this?

Been racking my brains for days on this .
Any help or advice appreciated
Thanks
Clive
 
assume the date is in mysql date/time stamp format or some other format recognised by strtotime. if not you will need to manipulate the input date.

to change the output format, alter the value of $format.

Code:
<?php
echo getSameDOW('2006-05-01');
function getSameDOW($date){
	$format = 'l, jS F Y';
	$historicDOW = date('N', strtotime($date));
	$thisDOW = date('N');
	if ($historicDOW === $thisDOW){
		return date($format, strtotime('today'));
	}
	if ($historicDOW < $thisDOW){
		return date($format, strtotime('last ' . date('l', strtotime($date))));
	}
  	return date($format,strtotime('this week ' . date('l', strtotime($date))));
}
?>
 
Many Many thanks for this.
Giving me the working code as well, a real bonus!!!
Best wishes
Clive
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top