binar
binar

Reputation: 356

Mysql between time and dates

Hi stackoverflow masters

Today problem with making a query in mysql, my table :

CREATE TABLE IF NOT EXISTS `hala_wyplaty_promocje` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `data_od` date NOT NULL,
  `data_do` date NOT NULL,
  `godzina_od` time NOT NULL,
  `godzina_do` time NOT NULL,
  `stawka` float NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;

--
-- Zrzut danych tabeli `hala_wyplaty_promocje`
--

INSERT INTO `hala_wyplaty_promocje` (`id`, `user_id`, `data_od`, `data_do`, `godzina_od`, `godzina_do`, `stawka`) VALUES
(1, 0, '2026-07-20', '2027-08-20', '00:00:00', '00:00:00', 2.5),
(3, 0, '0000-00-00', '0000-00-00', '00:00:00', '00:00:00', 1.7),
(5, 0, '0000-00-00', '0000-00-00', '00:00:00', '00:00:00', 1.7),
(7, 126, '0000-00-00', '2021-00-00', '00:00:00', '00:00:00', 3.2),
(9, 26, '0000-00-00', '0000-00-00', '11:15:00', '12:15:00', 0),
(11, 126, '0000-00-00', '0000-00-00', '11:15:00', '12:15:00', 5),
(13, 126, '0000-00-00', '0000-00-00', '10:00:00', '20:00:00', 7),
(15, 126, '2015-07-14', '2015-07-31', '12:00:00', '20:15:00', 8),
(17, 126, '2015-07-21', '2015-07-31', '12:00:00', '18:00:00', 12),
(19, 126, '2015-07-28', '2015-07-31', '15:00:00', '22:00:00', 22),
(21, 126, '2015-07-22', '2015-07-31', '10:00:00', '18:00:00', 0.15);

I want to get stawka value based on : if current date/time is between data_od+godzina_od to data_do+godzina_do. for now its giving me dates or hours i dont know how to merge it . cheers

Upvotes: 0

Views: 66

Answers (1)

mario.van.zadel
mario.van.zadel

Reputation: 2949

About the merging the DATE and the TIME field the following topic should help you: stackoverflow.com/questions/3307522

Then you can use SELECT stawka FROM hala_wyplaty_promocje WHERE NOW() BETWEEN ... AND ...

Upvotes: 1

Related Questions