Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich möchte eine Datumsliste erzeugen....

es sollen die vergangen (z.b. ) 100 Tage und die zukünfigen 10 Tage ausgegeben werden...

etwas so:

....

2007-09-02

2007-09-03

2007-09-04

2007-09-05

2007-09-06

2007-09-07

2007-09-08

2007-09-09

leider finde ich in den Datumsfunktion nicht so wirklich etwas hilfreichen...

ich möchte eine Datumsliste erzeugen....

Mit welcher Technologie denn?

oh sorry.... PHP

Bin zwar kein PHP-Experte, aber die Funktion date_modify sieht ganz vielversprechend aus:

PHP: date_modify - Manual

einfach und effektiv:

schnapp dir den aktuellen unix-timestamp

$timestamp = time();

und ziehe die sekunden hinzu, die ein tag hat

24x60x60 = 86400

$timestamp = $timestamp - 86400;

anschließend formatierst du dir den timestamp um

$datum = date("Y-m-d",$timestamp);

das alles packst du in eine schöne schleife mit einem zähler, der bis 100 zählt. anschließend kommt noch eine schleife, die ab dem heutigen tag 10 tage nochzählt...

einfach und effektiv:

schnapp dir den aktuellen unix-timestamp

$timestamp = time();

und ziehe die sekunden hinzu, die ein tag hat

$timestamp = $timestamp - 86400;

anschließend formatierst du dir den timestamp um

$datum = date("Y-m-d",$timestamp);

das alles packst du in eine schöne schleife mit einem zähler, der bis 100 zählt. anschließend kommt noch eine schleife, die ab dem heutigen tag 10 tage nochzählt...

Da find ich Date-Modify wesentlich einfacher...


$date = new DateTime("2007-09-06");
//-100 days, da die letzten 100 Tage
$date->modify("-100 days");
for($i = 0; $i < 110; $i++) //110 mal, da 10 Zukunftstage
{
$date->modify("+1 day");
echo $date->format("Y-m-d");
}
[/PHP]

Warum nicht gleich die Schleife negativ werden lassen :)


$date = new DateTime("2007-09-06");
for($i = 10; $i > -100; $i--) //110 mal, da 10 Zukunftstage
{
$date->modify("+$i day");
echo $date->format("Y-m-d");
}
[/PHP]

Oder so... so wach war ich heut morgen noch nicht. ;)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.