INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to validate a date - last day of ANY Month in any Year

How to validate a date - last day of ANY Month in any Year

(OP)
thread184-1006090: How do I validate a date ?

How to validate a date - last day of ANY Month in any Year
Here's a small effective function that will do it.

*
* FUNC Get_Last_Day_Of_Month
*
* Start at day 31 and keep going down/back in days til we find the last good day of this month

LPARAMETERS pdDate && pass in a date you know is valid, with a valid MONTH and YEAR, like "01/01/1999"
TRY
pdDate = CTOD(pdDate) && in case we send in a date as a string - in string format
CATCH
ENDTRY
nMonth = MONTH(pdDate)
nYear = YEAR(pdDate)

* Compute LAST DAY OF MONTH that was passed in
dNewDate = CTOD(' / / ')
nDay = 31
DO WHILE EMPTY(dNewDate) && when Date is invalid, date HighDate will be empty
dNewDate = CTOD(ALLTRIM(TRANSFORM(nMonth)) + '/' + TRANSFORM(nDay) + '/' + ALLTRIM(TRANSFORM(nYear)))
nDay = nDay - 1
ENDDO

RETURN dNewDate
*
* ENDFUNC
*

RE: How to validate a date - last day of ANY Month in any Year

I'm not exactly sure what you're trying to do, but there are more efficient ways to find the last day of a month. Assuming you're given a date, to find the last day of that month, you can do this:

CODE

LPARAMETERS pdDate

LOCAL ldLastDay

ldLastDay = GOMONTH(m.pdDate - DAY(m.pdDate) + 1, 1) - 1

RETURN m.ldLastDay 

This finds the first of the month, then goes forward a month, and then subtracts one day.

Tamar

RE: How to validate a date - last day of ANY Month in any Year

Besides, the old thread you referred to wasn't at all about determining the last day of a month. It was about verifying a date string is a valid date.

Bye, Olaf.

RE: How to validate a date - last day of ANY Month in any Year

getting the last day of a month can be done like this:

CODE --> Foxpro

CLEAR 

?GetLastDayOfMonth( DATE() )
?GetLastDayOfMonth( {12.02.2012} )

FUNCTION GetLastDayOfMonth as Date 
LPARAMETERS vDate as Date

    RETURN DATE( YEAR( GOMONTH( vDate , 1 ) ) , MONTH( GOMONTH( vDate , 1 ) ) , 1 ) - 1

ENDFUNC 

HTH

-Tom
https://www.blogger.com/profile/089031659767875220...

RE: How to validate a date - last day of ANY Month in any Year

Hi,

Or

? GoMonth(dDate, 1) - Day(GoMonth(dDate, 1))

hth

MarK

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close