web-dev-qa-db-fra.com

Requête MYSQL entre deux horodatages

J'ai l'entrée suivante dans ma table de base de données

eventName(varchar 100) -> myEvent
date(timestamp) -> 2013-03-26 09:00:00

et j'essaie d'utiliser la requête suivante;

SELECT * 
FROM eventList 
WHERE `date` BETWEEN UNIX_TIMESTAMP(1364256001) AND UNIX_TIMESTAMP(1364342399)

c'est-à-dire entre 2013-03-26 00:00:01 et 2013-03-26 23:59:59

mais il me donne 0 résultats.

J'ai essayé d'élargir la plage de dates sans succès et il y a clairement des résultats dans la plage.

toute aide est appréciée.

31
user2068441

Essayer:

SELECT * 
FROM eventList 
WHERE  `date` BETWEEN FROM_UNIXTIME(1364256001) AND FROM_UNIXTIME(1364342399)

Ou

SELECT * 
FROM eventList WHERE  `date` 
BETWEEN '2013-03-26 00:00:01' AND '2013-03-26 23:59:59'
50
Frank Conry

Essaye celui-là. Ça marche pour moi.

SELECT * 
FROM eventList 
WHERE DATE(date) 
BETWEEN '2013-03-26' AND '2013-03-27'
3
androsfat

Vous avez juste besoin de convertir vos dates en UNIX_TIMESTAMP. Vous pouvez écrire votre requête comme ceci:

SELECT *
FROM eventList
WHERE
  date BETWEEN
      UNIX_TIMESTAMP('2013/03/26')
      AND
      UNIX_TIMESTAMP('2013/03/27 23:59:59');

Si vous ne spécifiez pas l'heure, MySQL supposera que 00:00:00 correspond à l'heure indiquée. 

2
Amaynut
SELECT * FROM `orders` WHERE `order_date_time`  BETWEEN 1534809600 AND 1536718364
1
Ragu S Mech

Essayez ci-dessous le code. A travaillé dans mon cas. J'espère que cela t'aides!

    select id,total_Hour,
    (coalesce(weekday_1,0)+coalesce(weekday_2,0)+coalesce(weekday_3,0)) as weekday_Listing_Hrs,
    (coalesce(weekend_1,0)+coalesce(weekend_2,0)+coalesce(weekend_3,0)) as weekend_Listing_Hrs
    from
    select *,
    listing_duration_Hour-(coalesce(weekday_1,0)+coalesce(weekday_2,0)+coalesce(weekday_3,0)+coalesce(weekend_1,0)+coalesce(weekend_2,0)) as weekend_3 
    from 
    (
    select * , 
    case when date(Start_Date) = date(End_Date) and weekday(Start_Date) in (0,1,2,3,4) 
         then timestampdiff(hour,Start_Date,End_Date)
         when date(Start_Date) != date(End_Date) and weekday(Start_Date) in (0,1,2,3,4) 
         then 24-timestampdiff(hour,date(Start_Date),Start_Date)
         end as weekday_1,  
    case when date(Start_Date) != date(End_Date) and weekday(End_Date) in (0,1,2,3,4) 
         then timestampdiff(hour,date(End_Date),End_Date)
         end as weekday_2,
    case when date(Start_Date) != date(End_Date) then    
    (5*(DATEDIFF(date(End_Date),adddate(date(Start_Date),+1)) DIV 7) + 
    MID('0123455501234445012333450122234501101234000123450',7 * WEEKDAY(adddate(date(Start_Date),+1))
    + WEEKDAY(date(End_Date)) + 1, 1))* 24 end as  weekday_3,
    case when date(Start_Date) = date(End_Date) and weekday(Start_Date) in (5,6) 
         then timestampdiff(hour,Start_Date,End_Date)
         when date(Start_Date) != date(End_Date) and weekday(Start_Date) in (5,6) 
         then 24-timestampdiff(hour,date(Start_Date),Start_Date)
         end as weekend_1,  
    case when date(Start_Date) != date(End_Date) and weekday(End_Date) in (5,6) 
         then timestampdiff(hour,date(End_Date),End_Date)
         end as weekend_2
    from 
    TABLE_1
    )
0
Supriyanka Kharade

Essayez ce qui suit:

SELECT * FROM eventList WHERE
date BETWEEN 
STR_TO_DATE('2013/03/26', '%Y/%m/%d')
AND
STR_TO_DATE('2013/03/27', '%y/%m/%d')
0
Tenison

@Amaynut Merci

SELECT * 
FROM eventList 
WHERE date BETWEEN UNIX_TIMESTAMP('2017-08-01') AND UNIX_TIMESTAMP('2017/08/01');

ci-dessus mentionné, le code fonctionne et mon problème est résolu.

0
Jagdeep Singh