PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Last Friday of every month
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Last Friday of every month

Réponse
 
LinkBack Outils de la discussion
Vieux 14/03/2008, 03h12   #1
VamVan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Last Friday of every month

Can you tell me how to do this ?

suppose I have a date variable = '02/23/2008'

i need to know if this is the last friday of february....

let me know.
  Réponse avec citation
Vieux 14/03/2008, 03h39   #2
Andrés Robinet
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] Last Friday of every month

> -----Original Message-----
> From: VamVan [mailto:vamseevan@gmail.com]
> Sent: Thursday, March 13, 2008 9:13 PM
> To: php-general@lists.php.net
> Subject: [php] Last Friday of every month
>
> Can you tell me how to do this ?
>
> suppose I have a date variable = '02/23/2008'
>
> i need to know if this is the last friday of february....
>
> let me know.


My view...

$strDate = '02/23/2008';
//
$intDate = strtotime($strDate);
$numDaysInMonth = date('t', $intDate);
$dayOfWeek = date('w', $intDate);
$dayOfMonth = date('j', $intDate);
If ($dayOfWeek == 5 && $numDaysInMonth - $dayOfMonth < 7) {
echo "Friday Party!";
} else {
echo "Sorry dude, you missed it";
}

Btw, read the manual (and don't think to be so lucky to not found any bugs in my
code).

Regards,

Rob(inet)


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 |
TEL 954-607-4296| FAX 954-337-2695 |
Email: info@bestplace.net | MSN Chat: best@bestplace.net | SKYPE: bestplace |
Web: bestplace.biz | Web: seo-diy.com



  Réponse avec citation
Vieux 14/03/2008, 10h01   #3
Aschwin Wesselius
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

VamVan wrote:
> Can you tell me how to do this ?
>
> suppose I have a date variable = '02/23/2008'
>
> i need to know if this is the last friday of february....
>
> let me know.


$month = 3;
$year = 2008;

for ($day = 31; $day >= 21; $day--) { // maximum of 7 days, but
february starts at 28

$tmp_time = mktime(0, 0, 0, $month, $day, $year);

if (date('w', $tmp_time) === '5') { // 5 = friday

return date('d-m-Y', $tmp_time);
// return $day.'-'.$month.'-'.$year; // without the function
it is faster off course
// echo 'Yeah, friday!';
}
}

Something similar worked for me to find out when daylight saving time is.
--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

  Réponse avec citation
Vieux 14/03/2008, 11h02   #4
Richard Heyes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

VamVan wrote:
> Can you tell me how to do this ?
>
> suppose I have a date variable = '02/23/2008'
>
> i need to know if this is the last friday of february....


Work backwards from the 28th subtracting 86400 from your Unix timestamp
until you get to a Friday. Compare this with your variable.

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
  Réponse avec citation
Vieux 14/03/2008, 17h57   #5
tedd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

At 8:17 AM -0400 3/14/08, Eric Butera wrote:
>
>Just FYI you can use the word "last friday" in strtotime. So really
>you could check and see if the max day in a month is a friday and if
>not fall back on last friday. I didn't test it but I just thought I'd
>throw that out there.
>
>erics:~ eric$ php -r "echo date('n/j/Y', strtotime('last friday'));"
>3/7/2008


Eric:

When I read that, I went "Na, that can't be right" -- so I checked it.

You were right -- here it is:

http://webbytedd.com/b1/last-friday/

Thanks for the suggestion.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
  Réponse avec citation
Vieux 14/03/2008, 18h44   #6
Philip Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

On Mar 13, 2008, at 8:12 PM, VamVan wrote:

> Can you tell me how to do this ?
>
> suppose I have a date variable = '02/23/2008'
>
> i need to know if this is the last friday of february....
>
> let me know.


There are plenty of ways. Here's a couple:

OS X:
1. Finder > Applications > iCal (or Command-space for Spotlight, and
then type 'ical')
2. Click on Month (if not already selected)
3. Scroll to February
4. Look

Windows:
1. Double-click the clock in the task bar
2. Scroll to February
3. Look

HTH,
~Philip

PS... For a programmatic way, consult the PHP date functions...
  Réponse avec citation
Vieux 14/03/2008, 18h48   #7
Philip Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

On Mar 14, 2008, at 11:44 AM, Philip Thompson wrote:

> On Mar 13, 2008, at 8:12 PM, VamVan wrote:
>
>> Can you tell me how to do this ?
>>
>> suppose I have a date variable = '02/23/2008'
>>
>> i need to know if this is the last friday of february....
>>
>> let me know.

>
> There are plenty of ways. Here's a couple:
>
> OS X:
> 1. Finder > Applications > iCal (or Command-space for Spotlight, and
> then type 'ical')
> 2. Click on Month (if not already selected)
> 3. Scroll to February
> 4. Look
>
> Windows:
> 1. Double-click the clock in the task bar
> 2. Scroll to February
> 3. Look


Can't forget *nix:

1. Open a terminal and type the following
%> cal 2 2008


> HTH,
> ~Philip
>
> PS... For a programmatic way, consult the PHP date functions...


  Réponse avec citation
Vieux 14/03/2008, 19h03   #8
Eric Butera
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

On Fri, Mar 14, 2008 at 11:57 AM, tedd <tedd.sperling@gmail.com> wrote:
> At 8:17 AM -0400 3/14/08, Eric Butera wrote:
> >
> >Just FYI you can use the word "last friday" in strtotime. So really
> >you could check and see if the max day in a month is a friday and if
> >not fall back on last friday. I didn't test it but I just thought I'd
> >throw that out there.
> >
> >erics:~ eric$ php -r "echo date('n/j/Y', strtotime('last friday'));"
> >3/7/2008

>
> Eric:
>
> When I read that, I went "Na, that can't be right" -- so I checked it.
>
> You were right -- here it is:
>
> http://webbytedd.com/b1/last-friday/
>
> Thanks for the suggestion.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Hi Tedd,

Thanks for the writeup! You could streamline that a bit by using
getdate() and using the returned array values.
  Réponse avec citation
Vieux 14/03/2008, 19h44   #9
tedd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Last Friday of every month

At 1:03 PM -0400 3/14/08, Eric Butera wrote:
>On Fri, Mar 14, 2008 at 11:57 AM, tedd <tedd.sperling@gmail.com> wrote:
>
> >
>> You were right -- here it is:
>>
> > http://webbytedd.com/b1/last-friday/
>>

>
>
>Hi Tedd,
>
>Thanks for the writeup! You could streamline that a bit by using
>getdate() and using the returned array values.


Streamline?

Anyway that does the job that I can understand works for me. :-)

Cheers,

tedd

PS: As they say in Perl "More than one way to do it." or something to
that affect -- it's been a long time since I programmed in Perl.
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 15h27.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15019 seconds with 17 queries