Brian & Laura McGarvie
Welcome to Brian and Laura McGarvie’s homepage, find out more information on Brian M McGarvie and his it consultancy, and about our personal adventures and experiances…

SQL - Select using current day…

August 23rd, 2007 by Brian M McGarvie

I’ve had this problem a few times, and many people always ask me it… so here it is immortalised.

If you require to select all records added to your table for the current day use the following where clause - obviously ‘col’ should be the name of your datetime column…

Hope this helps you all as much as it has myself!
select *
from mytable
where datediff(day,getdate(),col)=0 and col <= getdate()

Posted in Programming, SQL

One Response

  1. logicbox symba

    Private Sub lm_Click()
    s1 = “select prof.nom_prof from ((((classe inner join r_pc on classe.code_classe=r_pc.code_classe) “
    s2 = “inner join prof on r_pc.code_prof=prof.cde_prof) “
    s3 = “inner join r_pm on prof.cde_prof=r_pm.code_prof)”
    s4 = ” inner join module on r_pm.code_module=module.code_mod )”
    s5 = ” where module.lib_mod=’” + lm + “‘”
    r_sql = s1 & s2 & s3 & s4 & s5
    Set tabl = bd.OpenRecordset(”select prof.nom_prof from ((((classe inner join r_pc on classe.code_classe=r_pc.code_classe) inner join prof on r_pc.code_prof=prof.cde_prof)inner join r_pm on prof.cde_prof=r_pm.code_prof)inner join module on r_pm.code_module=module.code_mod )where module.lib_mod=’” + lm + “‘”)
    While Not tabl.EOF
    lp.AddItem tabl![nom_prof]
    tabl.MoveNext
    Wend

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.