Courtman Paranoid Android Local time Today, 20:02 Joined Dec 8, 2001 Messages 34 Sep 9, 2008 #1 Hiya all I'm trying to write a query which looks back over the past six calendar months - i.e. from today back to 01-Mar-2008. Can anyone recommend the easiest way to do this in a query please? Thanks!
Hiya all I'm trying to write a query which looks back over the past six calendar months - i.e. from today back to 01-Mar-2008. Can anyone recommend the easiest way to do this in a query please? Thanks!
M MagicMan Registered User. Local time Today, 15:02 Joined Aug 28, 2008 Messages 186 Sep 9, 2008 #2 Assuming your table date is date format Code: strSql = Select * From yourtable Where yourdbdate > #' & Dateadd("m",-6,Date) & "#" If you want the first day of the month, then use Code: strSql = Select * From yourtable Where yourdbdate > #' & DateSerial(Year(Date()), Month(Date())-6,1) & "#"
Assuming your table date is date format Code: strSql = Select * From yourtable Where yourdbdate > #' & Dateadd("m",-6,Date) & "#" If you want the first day of the month, then use Code: strSql = Select * From yourtable Where yourdbdate > #' & DateSerial(Year(Date()), Month(Date())-6,1) & "#"
Courtman Paranoid Android Local time Today, 20:02 Joined Dec 8, 2001 Messages 34 Sep 9, 2008 #3 Brilliant, my SQL query now looks like this: Code: SELECT Sum([Log Entries].[Instr Apps]) AS [SumOfInstr Apps] FROM [Log Entries] WHERE [Log Entries].[Date] > DateSerial(Year(Date()), Month(Date())-6,1); and works perfectly. Thank you!
Brilliant, my SQL query now looks like this: Code: SELECT Sum([Log Entries].[Instr Apps]) AS [SumOfInstr Apps] FROM [Log Entries] WHERE [Log Entries].[Date] > DateSerial(Year(Date()), Month(Date())-6,1); and works perfectly. Thank you!
M MagicMan Registered User. Local time Today, 15:02 Joined Aug 28, 2008 Messages 186 Sep 9, 2008 #4 Glad I could help. Smiles bob