Hello, Guest!
Article about how to find day from date and year
Stack Overflow
How to get all possible years from the given day, day of the week, and month? I want to get the set of years which pertain to a specific date, week of the day and month . There are possibilities
How to get all possible years from the given day, day of the week, and month?
I want to get the set of years which pertain to a specific date, week of the day and month . There are possibilities that I can get various years from this pattern. Suppose Date is 15, Month is August and Week of the day is Tuesday then, How would I find the years that are valid? Is there a formula for this? FYI… Brute-force it in one line of Java code, as seen here: LocalDate.of( 2000 , Month.JANUARY , 1 ).datesUntil( Year.now( ).plusYears( 1 ).atDay( 1 ) ).filter( localDate -> localDate.getMonth( ).equals( Month.AUGUST ) ).filter( localDate -> localDate.getDayOfMonth( ) == 15 ).filter( localDate -> localDate.getDayOfWeek( ).equals( DayOfWeek.TUESDAY ) ).map( Year :: from ).forEach( System.out :: println ), yields 2000 2006 2017 2023. 5 Answers 5. Would this fully solve your problem? The idea behind this: Start from the specific date (August 15th) from year 0 if the date is on the specified weekday --> add it to your list add 1 year back to square 1. (till your specified MAX_DATE is reached) Edit: if your date is February 29th you should add following code (Because if you add 1 year to 0000-02-29 it will give you 0001-02-28, and from there on you will stay at the 28th) Heres a version with streams: Here is a simple formula you can do even in your head.You can find more info here: How to determine the day of the week, given the month, day and year. Take the last two digits of the year. Divide by 4, discarding any fraction. Add the day of the month. Add the month's key value: JFM AMJ JAS OND 144 025 036 146 Subtract 1 for January or February of a leap year. For a Gregorian date, add 0 for 1900's, 6 for 2000's, 4 for 1700's, 2 for 1800's, for other years, add or subtract multiples of 400. For a Julian date, add 1 for 1700's, and 1 for every additional century you go back. Add the last two digits of the year. Divide by 7 and take the remainder. Downvoted because it finds the weekday for a year, month, and monthday. The OP wants to find the year for a month, monthday, and weekday. This question relates to the classical Dommsday algo. A simple method to calculate is Kraitchik's method. Kraitchik method - w = d + m + c + y mod 7, where w is the day of the week (counting upwards from 1 on Sunday instead of 0 in Gauss's version), and d, m, c and y are numbers depending on the day, month, and year as in the following tables: For the Gregorian calendar, take the century of the year (ex, the year 1986 would be 1900, 2014 would be 2000). [Century/100] mod 4: 0 1 2 3 c: 0 5 3 1. For the Julian calendar, [Century/100] mod 7: 0 1 2 3 4 5 6 c: 5 4 3 2 1 0 6. Finally, the year number is obtained from this table (with 1 being subtracted from dates in January or February): Last two digits of the year y 00 06 17 23 28 34 45 51 56 62 73 79 84 90 0 01 07 12 18 29 35 40 46 57 63 68 74 85 91 96 1 02 13 19 24 30 41 47 52 58 69 75 80 86 97 2 03 08 14 25 31 36 42 53 59 64 70 81 87 92 98 3 09 15 20 26 37 43 48 54 65 71 76 82 93 99 4 04 10 21 27 32 38 49 55 60 66 77 83 88 94 5 05 11 16 22 33 39 44 50 61 67 72 78 89 95 6.
How to get month from date in sql server
How to find day from date and year



