Using Current Date 
Author Message
 Using Current Date
How can I run a query to display the current months data?  I pull a list of
the current months invoices from a 400,000 row table, but I will have to
change the date every day to reflect the days turnover results.

Is there a statement I can add to the WHERE clause to select the current
month or days data?



Wed, 24 Apr 2002 03:00:00 GMT
 Using Current Date

David,

SQL Server has the built-in function getdate() to return the current date
and time. If you prefer an ANSI standard equivalent, you can also use
CURRENT_TIMESTAMP.

Since most of us are "old-time" SQL Server hacks, we are most familiar with
getdate() and old habits are hard to change, so:

to get the month:

select datepart(m, getdate())

this returns a number between 1 and 12 (1 = January, 12 = December)

to get the current date, you can do:

select convert(char(10), getdate(), 102)

this returns the date in yyyy.mm.dd format.

The CONVERT function has a number of formatting options, all of which are
documented in Books Online.

Lastly, if you want the current date as datetime data type, just do:

select convert(datetime, convert(char(10), getdate(), 102))


Quote:
> How can I run a query to display the current months data?  I pull a list
of
> the current months invoices from a 400,000 row table, but I will have to
> change the date every day to reflect the days turnover results.

> Is there a statement I can add to the WHERE clause to select the current
> month or days data?



Wed, 24 Apr 2002 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. SQL FoxPro ODBC Table Query using Current Date

2. ((Current Date - Start Date)/(End Date - Start Date))*Contract Amt

3. Current date without current time

4. Using floor command in a SQL statement to find records with current date

5. Using floor command in a SQL statement to find records with current date

6. Using ADO: current record remains NOT current after Update

7. set a date dimension to current date

8. MYSQL - DEFAULT DATE as CURRENT DATE

9. finding the date closest to the current date

10. Where Date = Current Date

11. Q:get current date and then create date range

12. Fill a date field with the current date when a checkbox is checked


 
Powered by phpBB® Forum Software