×
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!
  • Students Click Here

*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.

Students Click Here

Jobs

replace just the year on a date field
4

replace just the year on a date field

replace just the year on a date field

(OP)
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

RE: replace just the year on a date field

2
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
https://www.doschke.name

RE: replace just the year on a date field

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 --> VFP

DO LOCFILE("icalloader.prg")

LOCAL IC AS iCalendar
LOCAL ICProc AS ICSProcessor

#DEFINE ICSURL		"https://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics"
#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

RE: replace just the year on a date field

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:
http://www.ml-consult.co.uk/foxst-10.htm

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

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: replace just the year on a date field

(OP)
Thanks a lot to both of you for the advance information

RE: replace just the year on a date field

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

RE: replace just the year on a date field

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 --> VFP

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
RRULE:FREQ=YEARLY;BYMONTH=1;BYDAY=3MO
SUMMARY:Martin Luther King Day
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010219
RRULE:FREQ=YEARLY;BYMONTH=2;BYDAY=3MO
SUMMARY:Presidents Day
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010528
RRULE:FREQ=YEARLY;BYMONTH=5;BYDAY=-1MO
SUMMARY:Memorial Day
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20010903
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=1MO
SUMMARY:Labor Day
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20011008
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=2MO
SUMMARY:Columbus Day
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20011122
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=4TH
SUMMARY:Thanksgiving
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 

RE: replace just the year on a date field

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: Calculating the date of Easter

(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

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!

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