Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Select in base alla Data

    Ciao a Tutti,
    dunque ho un "topic_time" che è un VARCHAR(20) contenente la data di inserimento di un Topic in questo formato: 2002-10-12 19:32

    Io vorrei che venissero visualizzati SOLO i topic che hanno MENO di 30 giorni. Qualcosa del tipo "WHERE now()-topic_time<=30" . Non sono molto pratico ancora con le date dell'SQL.

    Chi mi aiuta? grazie 1000.

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    240

    DATA_SUB

    usa la sintassi

    WHERE CAMPO_DATA < DATE_SUB(NOW(),INTERVAL 30 DAY)

    P.S. NON MI RICORDO SE E' DAY O DAYS PROVALI ENTRAMBI

  3. #3
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    select * from tabella where campo_data > now() - interval 30 day
    oppure
    select * from tabella where campo_data > now() - interval 1 month
    vedi quale ti è più utile.

    ...se fossero date. trasforma il campo varchar nel formato adatto a gestire le date (datetime).

  4. #4
    Grazie x l'aiuto...
    dunque la query singolarmente funziona...ma mi son ritrovato ad applicarla nelle pagine PHP del FORUM ed ho avuto problemi. La query originale è la seguente:

    codice:
    $sql = "SELECT f.forum_id, f.forum_type, f.forum_pass, f.forum_access, f.forum_name, f.forum_rules, u.".$usname.", u.".$usid.",m.forum_id,m.user_id FROM ${prefix}_splattforum_forums f, ".$user_prefix."_users u, ${prefix}_splattforum_mods m WHERE f.forum_id = '$forum' AND m.forum_id = '$forum' AND m.user_id = u.".$usid."";
    aggiungendo al WHERE "AND" + uno dei vostri aiuti, mi da errore.

    Sapete aiutarmi?

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    240

    che errore ti da????

    scrivi la query che va in errore......

    che errore ti da????

  6. #6
    Scusami, avevo sbagliato.

    Allora la QUERY ORIGINALE FUNZIONANTE E':

    codice:
                    $sql = "SELECT t.*, u.".$usname." FROM ${prefix}_splattforum_forumtopics t left outer join ".$user_prefix."_users u on t.topic_poster = u.".$usid." WHERE t.forum_id = '$forum' ORDER BY highlight desc, topic_time DESC LIMIT $start, $topics_per_page"; #teo aggiunto order by highlight per bloccare msg in alto
    QUELLA CHE MI DA ERRORE E' LA SEGUENTE:

    codice:
                    $sql = "SELECT t.*, u.".$usname." FROM ${prefix}_splattforum_forumtopics t left outer join ".$user_prefix."_users u on t.topic_poster = u.".$usid." WHERE t.topic_time<DATE_SUB(NOW(),INTERVAL 30 DAY) AND t.forum_id = '$forum' ORDER BY highlight desc, topic_time DESC LIMIT $start, $topics_per_page"; #teo aggiunto order by highlight per bloccare msg in alto
    MI APPAIONO DEI RISULTATI, MA IN UN ORDINE STRANO! E NON NELL'ORDINE DI ULTIMA RISPOSTA ALLA DISCUSSIONE.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.