Print Page | Close Window

SQL for dates

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=24609
Printed Date: 28 March 2026 at 11:06pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: SQL for dates
Posted By: suedechaser
Subject: SQL for dates
Date Posted: 10 October 2007 at 11:55pm
Hi all,

I posted this question in another forum with no response - so i'll try here.

Could someone please show me corect MSSQL string would be for all records up to and including today.

Something like ...strSQL = strSQL + "WHERE th.my_date < OR = Now()"

I have searched and tried many options but cannot get anything to work.

Help Please??




Replies:
Posted By: dj air
Date Posted: 11 October 2007 at 2:47pm
this depends on the database, the below is for MSSQL
 
strSQL = strSQL + "WHERE th.my_date < '" &  Now() &"' "
for access its this one below (not 100% sure if not try without the ' ', been ages since used access)
 
strSQL = strSQL + "WHERE th.my_date < '#" & Now() &"#' "


Posted By: WebWiz-Bruce
Date Posted: 11 October 2007 at 4:53pm
Not sure if Now() would work with SQL Server, but the following is taken from code I wrote yesterday to do the same thing:-

tblHostingService.Renewal_Date <= GetDate();

GetDate() is SQL Servers version of vbScripts Now()

This of course includes the time as well so isn't 100% accurate, there are other more precise methods but can't remember them off-hand.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: suedechaser
Date Posted: 12 October 2007 at 1:18am
Hi dj / Borg,

Thanks. GetDate() appears to work well with < GetDate() and <=GetDate().

Why doesn't it work with = GetDate() or > GetDate()?

suede


Posted By: shakir
Date Posted: 18 November 2007 at 7:48am
In SQL no OR try <=
after that check the date format, you need to use cast or convert to change the date

convert(datetime,DateField ,103)


Posted By: WebWiz-Bruce
Date Posted: 18 November 2007 at 9:39am
With SQL you can use BETWEEN eg:-

WHERE DBfield BETWEEN Date1 AND Date2

Replace DBfield with the name of the database field and Date1 and Date2 with the 2 dates


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net