CodeIgniter Forums
count how may records are AM vs. PM - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: count how may records are AM vs. PM (/showthread.php?tid=10561)



count how may records are AM vs. PM - El Forum - 08-04-2008

[eluser]new_igniter[/eluser]
Hello,
I have a DB with mysql a standard timestamp in the format of 2008-01-23 11:44:16

Can someone help me with the mysql syntax for counting the number of records with a time in the AM and PM. It could be 2 different queries, but I havent been able to figure it out.


count how may records are AM vs. PM - El Forum - 08-04-2008

[eluser]Armchair Samurai[/eluser]
I'd do it like this - retrieve two records from the table, the first being AM totals and the second PM:
Code:
SELECT COUNT(*) AS `times`
FROM `foo`
WHERE HOUR(`bar`) < 12
UNION
SELECT COUNT(*)
FROM `foo`
WHERE HOUR(`bar`) >= 12



count how may records are AM vs. PM - El Forum - 08-05-2008

[eluser]new_igniter[/eluser]
thanks so much!