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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace just the year on a date field 4

Status
Not open for further replies.
Jan 20, 2007
237
US
Hi everyone little late but happy new year
just a silly question.
i have a table that has a date field named "Hdate" and a few records with different dates as those are holidays in USA so i want each year to change just the year of those dates with the current year
for example.
now i have in the field Hdate these records

05/30/2018 &&this is memorial day
07/04/2018 &&this is independence day

so i want each beginning of the year, click on a button use the table holiday and go through the table and replace the year with the year(date())
so i just tried to go to the first record and did the following.

replace year(hdate) with year(date())
of course it did not work for me.
any help is very appreciated
 
You nee
Code:
replace hdate with gomonth(hdate,12)

Cautious to only replace in the records you copied from last year. And only do that once.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Landfla,

A few US holidays cannot be determined that way: for the most important ones, that are observed nation-wide, Birthday of Martin Luther King, Jr., Washington's Birthday, and Thanksgiving are not fixed in the calendar.

If this is relevant to you, you must incorporate some logic in your application to handle such moveable events. The CalendarCalc library at VFPX incorporates a CalendarEvents class, and the definition of the USA main events is already included. You may find there an example short program that demonstrates, for a given year, how to fetch the yearly events.

Alternatively, you can also use the iCal4VFP library (again, a VFPX project) to integrate iCal files available from different sources (for instance, from CalendarLabs).

This is adapted from one of the examples in the iCal4VFP documentation, and to run it you have to have the library and its dependencies installed in your computer:
Code:
DO LOCFILE("icalloader.prg")

LOCAL IC AS iCalendar
LOCAL ICProc AS ICSProcessor

#DEFINE ICSURL		"[URL unfurl="true"]https://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics"[/URL]
#DEFINE ICSCURSOR	"tmpICS"

m.ICProc = CREATEOBJECT("ICSProcessor")

* read the ICS file from disk
m.IC = m.ICProc.ReadURL(ICSURL)

* is everything ok?
IF !ISNULL(m.IC)

	* send it to a cursor and display it
	m.ICProc.ICSToCursor(m.IC, "EVENTS", ICSCURSOR)
	BROWSE LAST FOR YEAR(Start) = 2019

ENDIF

m.IC = .NULL.
m.ICProc = .NULL.

This will result in

Clipboard01_jsb7lm.png
 
Landfla,

Just to follow up Atlopes' post, we have a ready-made PRG which will fill a DBF with the dates of 17 US holidays and notable dates for two years ahead.

If you would like a copy, see here:

It can easily be customised for non-US notable dates.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I've been away a little and just seeing this. The complete list of US holidays that vary from year to year is (I think):

Martin Luther King Day - 3rd Monday in January
Presidents Day - 3rd Monday in February
Memorial Day - last Monday in May
Labor Day - 1st Monday in September
Columbus Day - 2nd Monday in October (same day as Canadian Thanksgiving, I believe)
Thanksgiving - 4th Thursday in November

I think that's all the floating national holidays.

Tamar
 
Taking from Tamar's list, this would be an alternative way to set US non-fixed national holidays, by using the Recurrence Rule processor in the iCal4VFP library.

Code:
DO LOCFILE("icalloader.prg")

SET CENTURY ON

* set for a year between 2001 and the year of the calendar limit (2050, as set)
#DEFINE CALENDARYEAR 2019
#DEFINE CALENDARLIMIT {^2050-12-31 23:59:59}

LOCAL ICSSource AS String
LOCAL ICS AS ICSProcessor
LOCAL iCal AS iCalendar
LOCAL iEvent AS iCompVEVENT
LOCAL EventIndex AS Integer
LOCAL Rule AS iCalPropRRULE
LOCAL RuleCursor AS String
LOCAL EventName AS String

* RRULE (in these cases quite simple, actually) highlighted for each event
TEXT TO m.ICSSource NOSHOW
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//iCal4VFP
VERSION:2.0
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010115
[highlight #FCE94F]RRULE:FREQ=YEARLY;BYMONTH=1;BYDAY=3MO
SUMMARY:Martin Luther King Day[/highlight]
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010219
[highlight #FCE94F]RRULE:FREQ=YEARLY;BYMONTH=2;BYDAY=3MO
SUMMARY:Presidents Day[/highlight]
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010528
[highlight #FCE94F]RRULE:FREQ=YEARLY;BYMONTH=5;BYDAY=-1MO
SUMMARY:Memorial Day[/highlight]
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010903
[highlight #FCE94F]RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=1MO
SUMMARY:Labor Day[/highlight]
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20011008
[highlight #FCE94F]RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=2MO
SUMMARY:Columbus Day[/highlight]
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20011122
[highlight #FCE94F]RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=4TH
SUMMARY:Thanksgiving[/highlight]
END:VEVENT
END:VCALENDAR
ENDTEXT

m.ICS = CREATEOBJECT("ICSProcessor")
m.iCal = m.ICS.Read(m.ICSSource)

CREATE CURSOR USEvents (EventName Varchar(50), EventDay Date)

FOR m.EventIndex = 1 TO m.iCal.GetICComponentsCount("VEVENT")

	m.iEvent = m.iCal.GetICComponent("VEVENT", m.EventIndex)
	m.EventName = m.iEvent.GetICPropertyValue("SUMMARY")
	m.Rule = m.iEvent.GetICproperty("RRULE")

	m.RuleCursor = m.Rule.CalculateAll(DTOT(m.iEvent.GetICPropertyValue('DTSTART')), CALENDARLIMIT, .NULL., .NULL., .NULL.)

	SELECT EventName, EventDay ;
		FROM USEvents ;
	UNION ;
	SELECT CAST(m.EventName AS Varchar(50)) AS EventName, TTOD(rul.localtime) AS EventDay ;
		FROM (m.RuleCursor) rul ;
		WHERE YEAR(rul.localtime) = CALENDARYEAR ;
	INTO CURSOR USEvents ;
	ORDER BY 2

	USE IN (m.RuleCursor)

ENDFOR

BROWSE
 
You can also write functions determining such dates in VFP, for example, shown here: thread184-1141890

The definition of Easter holidays also can be taken from thread184-917615

Bye, Olaf.



Olaf Doschke Software Engineering
 
Regarding the date of Easter ....

The PRG I referenced (in my previous post in this thread) incorporates that calculation.

You can also find it here: faq184-3807

(and note the comment about the adoption of the Gregorian calendar, 1582 - 1587 and 1752).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top