Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Last day of the week
Message
 
À
28/07/2004 15:54:50
Sony Joseph
Dovenmuehle Mortgage Inc
Schaumburg, Illinois, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00928869
Message ID:
00928991
Vues:
18
>Hi,
>
>Do you have a function that can return the last day of the week if a pass the number that is returned from the Week()?
>
>For eg: if I pass 31 to the function , I should get 07/31/2004, which is the last day of that week.
>
>TIA

Sony,

This isn't as easy a question as it might appear. First, does the first week contain Jan. 1? Or is it the first full week of the year? Second, is the first day a Sunday?

To answer the question, however, and assuming that the first day is a Sunday and that the first week of the year contains Jan. 1.
FUNCTION LastDOW(tddate AS Date)

  LOCAL lnweeks AS Integer, ldreturndate AS Date
  tddate = DATE()
  lnweeks = WEEK(tddate, 1, 1) - 1
  ldreturndate = DATE(YEAR(tddate), 1, 1) + (lnweeks * 7)
  ldreturndate = ldreturndate + 7 - DOW(ldreturndate, 1)
  RETURN ldreturndate
ENDFUNC
Update: One reason for taking into consideration the first week of the year is that if the first day of the week changes, then all code that expects it to be a Sunday breaks. We've had this situation at work and we've been working on it for months. In the above, all you have to do is either change the parameter passed to the DOW() function.
George

Ubi caritas et amor, deus ibi est
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform