troubleshooting Question

Get weeknumber and year from date

Avatar of Stef Merlijn
Stef MerlijnFlag for Netherlands asked on
Delphi
4 Comments2 Solutions217 ViewsLast Modified:
Hi,

I need a function that will return a string with the weeknumber and the calculated year for any date on monday (first day of the week).

Normally it would by easy:
IntToStr(WeekOf(myDate)) + ' ' + IntToStr(YearOf(MyDate))
But, when week of given date is arount 1 january than it should determine year based on following criteria.
If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year.

Example:
Week 1 of 2014 starts on 30-12-2013 till 6-1-2014
Running the code above would result in Week 1 Year 2013, where it should be Week 1 Year 2014.
ASKER CERTIFIED SOLUTION
Sinisa Vuk
Software architect
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros