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 date-problem

Empfohlene Antworten

Veröffentlicht

Hallo liebe Leute!

Folgendes Problem:

Diese Tabelle ist gegeben:

nr. | datum | tage online

1 2005-01-01 30

2 2005-02-01 30

3 2005-03-01 40

nr. = auto_increment

datum = date

tage online = int

Angenommen, wir hätten heute den 31.03.2005, möchte ich folgende

Ergebnisse haben:

nr. | x tage zu lang online

1 60

2 29

... welches der Berechnung

--> aktuelles Datum - (Datum + Tage online)

entspricht.

Ich bitte Euch herzlichst darum, mir den passenden Query dafür zu schreiben.

Wenn möglich, dann BITTE den GENAUEN Query, denn die Zeit ist sehr knapp.

Meine Version ist 4.0.23. Leider bietet mein Provider nur diese alte Version an.

Vielen Dank !

... welches der Berechnung

--> aktuelles Datum - (Datum + Tage online)

entspricht.



select Nr, TO_DAYS(CURRENT_DATE) - (TO_DAYS(Datum) + Tage Online) zu_Lang 

from Tabelle 


Ist ungetestet...

TO_DAYS(date)

Given a date date, returns a daynumber (the number of days since year 0).

mysql> SELECT TO_DAYS(950501);

-> 728779

mysql> SELECT TO_DAYS('1997-10-07');

-> 729669

TO_DAYS() is not intended for use with values that precede the advent of the Gregorian calendar (1582), because it does not take into account the days that were lost when the calendar was changed.

Remember that MySQL converts two-digit year values in dates to four-digit form using the rules in Section 11.3, “Date and Time Typesâ€. For example, '1997-10-07' and '97-10-07' are seen as identical dates:

mysql> SELECT TO_DAYS('1997-10-07'), TO_DAYS('97-10-07');

-> 729669, 729669

For other dates before 1582, results from this function are undefined.

http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

Bei der MySQL-Dokumentation werden sie immer geholfen ;)

Felder sind datum und online...


SELECT *,DAYOFYEAR(FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(ADDDATE(datum, INTERVAL online DAY))))	

FROM datum

Zum Testen kannst Du auch NOW() durch '2005-03-31' ersetzen...

Edit: Nimm das Statement meines Vorposters, wenn's funktioniert, meins ist zu umständlich ;)

Und meins funktioniert nur innerhalb eines Jahres...

Vielen vielen Dank :)

Jemand hat mir noch eine Lösung geschrieben:

SELECT

praknr,

TO_DAYS(NOW()) - (TO_DAYS(datum) + online) AS XTageZuLangeOnline

FROM

prak

WHERE

TO_DAYS(datum) + online < TO_DAYS(NOW())

ORDER BY

XTageZuLangeOnline DESC

:)

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.