Stefan Höhn authored on08/11/2018 00:44:20 • GitHub committed on08/11/2018 00:44:20
Showing1 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
1
+<?php
2
+
3
+// Termine für regelmäßige Treffen zb. Jeden 2. Donnerstag im Monat
4
+
5
+/**
6
+   *
7
+   *  Gets the first weekday of that month and year
8
+   *
9
+   *  @param  int   The day of the week (0 = sunday, 1 = monday ... , 6 = saturday)
10
+   *  @param  int   The month (if false use the current month)
11
+   *  @param  int   The year (if false use the current year)
12
+   *
13
+   *  @return int   The timestamp of the first day of that month
14
+   *
15
+   **/ 
16
+function get_first_day($day_number=1, $month=false, $year=false, $week)
17
+{
18
+$daystowait=($week-1)*7+1;
19
+$month=($month === false) ? strftime("%m"): $month;
20
+$year=($year === false) ? strftime("%Y"): $year;
21
+$first_day = $daystowait + ((7+$day_number - strftime("%w", mktime(0,0,0,$month, 1, $year)))%7);
22
+return mktime(0,0,0,$month, $first_day, $year);
23
+}
24
+
25
+
26
+// These variables  are to configure
27
+$tag=4;
28
+//day  of the week
29
+$tagname="Donnerstag";
30
+//day
31
+$woche=2;
32
+//the week beginnig with 1-4
33
+
34
+
35
+$monat=date("m");
36
+$jahr=date("y");
37
+$datum_live = date("d,m,y");
38
+$datum_termin=strftime("%d-%m-%Y", get_first_day($tag, $monat, $jahr, $woche));
39
+// echo "datum_live =".$datum_live."datum_termin=".$datum_termin;
40
+$tages_differenz = date("d")-strftime("%d", get_first_day($tag, $monat, $jahr, $woche));
41
+// echo $tages_differenz;
42
+if ($tages_differenz > 0){
43
+$monat = $monat + 1;
44
+}if ($monat > 12){
45
+$monat = 1;
46
+$jahr = $jahr +1;}
47
+// this will output the 2. Donnerstag of 
48
+// aktuelles Monat und Jahr(wed 03-01-2007)
49
+echo $tagname ." ".strftime("%d-%m-%Y", get_first_day($tag, $monat , $jahr , $woche));
50
+// Script ist hier zu Ende.
51
+?>