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.

MYSQL: Datensätze löschen, wenn Datum > akt. Datum

Empfohlene Antworten

Veröffentlicht

Hallo!

Stehe vor folgendem Problem:

Wie kann ich eine MYSQL Abfrage erstellen, die mir alle Einträge löscht dessen Datum (in einem eigenen Feld Datum) kleiner oder gleich als das aktuelle datum ist?

Also z.B:

Die Tabelle:

Index Inhalt Datum

1 bla 01.01.2006

2 abc 03.01.2006

3 cba 12.12.2005

Also wenn ich den SQl Befehl am 01.01.2006 ausführe, dann sollen die Einträge mit Index 1+3 gelöscht werden, da Ihr Datum kleiner gleich dem aktuellen Datum ist.

Besten Dank im Voraus für eure Tipps.

mfg

Wie hast du denn das Datum in der Tabelle gespeichert? Ich hoffe mal als date und nicht als char.

DELETE * FROM TABELLENNAME WHERE Datum <= $datumheute

So in etwa sollte das funktionieren. $datumheute muss natürlich vorher entsprechend gesetzt werden.

Kurzer Hinweis: MySQL speichert Datumswerte im Format YYYY-MM-DD.

Wenn PHP zur Abfrage verwendet wird, kann man der Variablen $datumheute den Wert

date("Y-m-d")

zuweisen (ungetestet).

Warum nicht mit Boardmitteln?

http://dev.mysql.com/doc/refman/4.0/de/date-and-time-functions.html

CURDATE(), CURRENT_DATE

Gibt das Datum von heute im 'YYYY-MM-DD'- oder YYYYMMDD-format zurück, abhängig davon, ob die Funktion in einem Zeichenketten- oder in einem numerischen Zusammenhang benutzt wird:

mysql> select CURDATE();

-> '1997-12-15'

mysql> select CURDATE() + 0;

-> 19971215

Gruß Jaraz

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.