Link to home
Start Free TrialLog in
Avatar of prowebinteractive
prowebinteractive

asked on

vb get mysql number of records with todays date

I need to get the number of records created today in mySQL database
Avatar of ibost
ibost

Does your table have a column for "DateInserted"?

select
   count(*)
from
   MyTable
where
      DateInserted >= cast(datediff(day, 0, getdate()) as datetime)
and DateInserted <   cast(datediff(day, 0, dateadd(d, 1, getdate())) as datetime)


This drops the time portion from the date (effectively making '1/1/2006 12:32:22' equal to '1/1/2006 00:00:00', or 12 am today)
cast(datediff(day, 0, getdate()) as datetime)

this pushes the day portion forward one day (so '1/1/2006 12:32:22' becomes 1/2/2006 12;32:22', and then from there we drop the time portion)
dateadd(d, 1, getdate())


so now the query asks for records where DateInserted is greater than or equal to '1/1/2006 00:00:00' and less than '1/2/2006 00:00:00'


Avatar of prowebinteractive

ASKER

ok good, how do I get the count in a messageBox
ASKER CERTIFIED SOLUTION
Avatar of ibost
ibost

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial