SELECT Where Date &>= 14 Months Ago


I need a select statement with the condition that the date (a timestamp with format yyyy-mm-dd) is either equal to or longer than 14 months from today's date.

I am using SQL Server

Can anyone point me in the right diretion?


View Replies


How To Get Date From 3 Months Ago

Hi all,How to get the date from the 3 months ago? So, if user enter a date (10/10/2006), how can I get to 07/10/2006.Thanks in advance...

View Replies View Related

Date Difference In Months

Hi to all,

I want to make an sql query that will subtract two dates and the difference will be number in months.

i have this table TestTable with Fields ACost, Adate, AMonth

my formula is this X = (Now-Adate), should give me number in months
and Y = (ACost/AMonth)
i want to get the product of X and Y, (X*Y).

how can i make this in sql views?

can anyone help me with this?

thanks a lot!

best regards,


View Replies View Related

Expression Where Date Is 3 Months Ago?

What is the correct code for an expression where my "datetime" field is greater then or equal to 3 months ago?

View Replies View Related

Date In Current Year Or Last Two Months


I had a requirement to filter records for the current year only... I went back to the user and explained that the logic wasn't sound... eg if somebody did the search early in January then they would probably get no results back. My suggestion was to go back two months if the current date is in January or february.

So, this is what I have.......

Code Snippet

where cs.startdate > case when year(cs.startdate) = year(getdate()) and month(getdate()) > 2 then
convert(char(4),year(getdate()))+'-01-01' else dateadd(month,-2,getdate()) end

Is there a neater/better way of coding this?


View Replies View Related

Select Last Months Data

Hi, i am trying to create a t-sql statement that will retrieve last months data (ie. if i run the query on 9th August, i only want to retrieve Julys data, 1st Sept will retrieve all of Augusts data etc). The query will be used once a month to populate a table, can anyone advise me on the correct where clause to use ?

Thanks in advance


View Replies View Related

How To Select Only Three Months Recored From Database

Hi guys,
Could anyone help me to write sql query to select only three months record from database
if the cur month is march then i need jan, feb and mar data , if it is jan, then i need nov , dec and jan can i write sql query for this, i need this for creating reports
and also how cal i write queries based on days...mean to say that i need to select all records of particular month that falls on monday or tuesday...
Help me out.
Thanks in advance

View Replies View Related

Select Query To Get Last 6 Months Data

I need to write a select query to get last six months data from a table , on monthly wise.Can anyone help me in writing this query
I am using sql server 2000.



View Replies View Related

Getdate() To Select Dates Less Than 15 Months

I need help. I want to select dates less than 15 months, as i am new to sql server , can anyone advise me.

I tried this query but it gave me the dates that are greater than 15 months

Selec calendardate from table
where calendardate < getdate()-457


View Replies View Related

T-SQL Scritp To Calculate The Last 6 Months Of Data In A Date Field.

Hi there,

if any body out there has done this before, can you please post the T-SQL script that calculate whatever last months of data based on a Date field.

Thanks very much,


View Replies View Related

Select Data From Table An Return All All Months

I have the following query:SELECT Month, Sum(Hits) AS Hits FROM tblHits GROUP BY Month ORDER BYMonthUnfortunately it only returns rows for months that have data assignedto them.How can I tweak this so that months 1-12 are returned, and Hits = 0 formonths with no data in the base table?Thanks.

View Replies View Related

Selecting Data Within 1 Month, 6 Months, 12 Months

I have the following table

FeedBack Type Date

test2 positive 03/15/08

tes3 negative 03/01/08

.. ....

in my page i need to select the number of negative/positive comments within the last

1 month, 6 months, 12 months

How can I accomplish that?

View Replies View Related

How To Select All Dates Upto Todays Date And Include The First Next Future Date

how can i select all dates upto todays date and include the first next future date in a given data base

say todays date was the 01/06/2006 (MM,DD,YYYY)

below is a mock data base
id date (MM,DD,YYYY)
1 01/02/2006
2 01/04/2006
3 01/06/2006
4 01/09/2006
5 01/20/2006

i want to select all dates equal or less that 01/06/2006 and include the first next future date .. and in this case it would be 01/09/2006

so the results would return

1 01/02/2006
2 01/04/2006
3 01/06/2006
4 01/09/2006

View Replies View Related

Select A Date Minus Whatever Todays Date Is?

At the moment i have a query that is dependent on a date which is 42 days before whatever the date may be today.

The statement in my query I have to use is:

MailDate <= '2008-01-05'

I am wondering if i could make that statement automatically take off 42 days from todays date?

View Replies View Related

Date Select Query - Select Between Two Dates

have a table with students details in it, i want to select all the students who joined a class on a particular day and then i need another query to select all students who joined classes over the course of date range eg 03/12/2003 to 12/12/2003.

i have tried with the following query, i need help putting my queries together
select * from tblstudents where classID='1' and studentstartdate between ('03/12/2004') and ('03/12/2004')

when i run this query i get this message

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

the studentstartdate field is set as datetime 8 and the date looks like this in the table 03/12/2004 03:12:15

please help

View Replies View Related

Select Where Date = Todays Date

I have a table with a field 'service_date' held as datetime. I would like to select from the table where the service date is equal to today. The input is dd/mm/yy.



View Replies View Related

How To Select The Date Part Of A Date

I use smalldatetime for a datetime and i just display the date part
i'd like to compare the date part of the smalldatetime and the date i have
how can i do that ?
I know we can select the day,month or year ...
If you know a link where i could find different kinds of example about sql command it would be great to


View Replies View Related

Can't Select Date

hi, my DatePost field in the database formated as 2/15/2006 11:40:46 AM . i try to manually give a date (no) but it give me error. the error come from myReader!. help me  to correct, thanks no = "2152006"        Dim myConn As SqlConnection        Dim myCmd As SqlCommand = New SqlCommand        Dim myReader As SqlDataReader        Dim strSQL As String        myConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))        strSQL = "SELECT Author FROM Booktbl WHERE cast(Date as datetime) ='" & no & "'"        myCmd.CommandText = strSQL        myConn.Open()        myCmd.Connection = myConn        myReader = myCmd.ExecuteReader        myReader.Read()        Author = myReader("Author")        myReader.Close()        myConn.Close()        lblShow.Text = Subject

View Replies View Related


I am trying to create a SELECT statement using a date. No data returns. However if I use the same Select Statement using ID or any other column it works fine. Is there a trick to using a date in a select statement?

("Select * From Events WHERE Event_Date Like '%" & 12/21/2004 & "%'" , DBConn)

View Replies View Related

Select Between Date

I am trying to get al the rows from table1 where datetime is between 9:00AMyesterday and 9:00AM today if the time now is less than 9:00AM. Otherwise itshould return all where datetime>9:00 AM today.Is this possible as a query in sql2000?

View Replies View Related

Date Select

I have the following fields in a table

Cost StartDate EndDate

How do find how much something cost in a given date? e.g. 15/3/2005

Thanks in Advance.

View Replies View Related

Select Date Help

I want to select all orders from table orderdetails where the month of orderdate is = to November and year of orderdate = 2004. How would I code this? orderdate is a datetime sql field.

View Replies View Related

Select Date


I'm trying to get all the records in my table that have a specific date. But I get no results.

The date column has the data type datetime and is stored like, for example, 11/01/2008 14:45:17 (dd/mm/yyyy)

So if I want to see al the records with date 11 januari 2008 I tried to do

FROM MyTable
WHERE date = '11/01/2008'

I also tried this

FROM MyTable
WHERE date LIKE '11/01/2008%'

But I get no results or no error message.

I checked the forum for an answer and found this solution

MyDateColumn >= '20060114' and
MyDateColumn < '20060115'

but that doesn't work either.

Can someone please tell me what I'm doing wrong.

Thanks in advance

View Replies View Related

How To Select Date Only

I am developing C# application and storing data in SQL 2005.

I have a datetime field and i want to select all records which has a specefic date regardless of time..

for example:

21/7/2008 12:40:32
21/7/2008 23:45:00

i want to select both because both has the same date

View Replies View Related


Hi All... I have a table that has a field called LogDateTime whose type is datetime.

How do I specify the WHERE clause if I want only those records that are say from the last three days? Such as WHERE (LogTimeDate < Today - 3 days)...

Thanks for any help!!! -- Curt

View Replies View Related

Sql Select To Include Date?

I have a table of parts and want to display some statistics from it.  The parts table has several fields in it, but the two that I need to use in my sql select queries are "PartUserID" and "DateUseBy", but I don't know how to use the "dateuseby" in the second example.Can someone help me out with #2?1. Display the total number of parts owned by a user:SQL Query:        SelectCommand="SELECT COUNT (*) FROM [ZCPart] WHERE (ZCPart.PartUserId = @PartUserId)"        OnSelecting="sqlPartCount_Selecting">        <SelectParameters>            <asp:Parameter Name="PartUserID" />        </SelectParameters>Code-behind:    protected void sqlPartCount_Selecting(object sender, SqlDataSourceSelectingEventArgs e)    {        e.Command.Parameters["@PartUserID"].Value = Membership.GetUser().ProviderUserKey;    }    2. Display the total number of parts owned by a user that are to be used in the current year. The table has a field "dateuseby" that should be used for the "Where" but I don't know how to get it.SQL Query:How to I include the "usebydate" so that it will use 2008 as the year ? I wrote the following query as an example of what I'm trying to get.        SelectCommand="SELECT COUNT (*) FROM [ZCPart] WHERE (ZCPart.PartUserId = @PartUserId, ZCPart.DateUseById = @PartUseById)"         onselecting="sqlPartYearCount_Selecting">        <SelectParameters>            <asp:Parameter Name="PartUserID" />            <asp:Parameter Name="DateUseByID" />        </SelectParameters>Code-behind:    protected void sqlPartYearCount_Selecting(object sender, SqlDataSourceSelectingEventArgs e)    {        e.Command.Parameters["@PartUserID"].Value = Membership.GetUser().ProviderUserKey;                // ? How do I change the date in the field to be in "2008" format and then put that in the sql query?        //e.Command.Parameters["@DateUseByID"].Value = currentYear;        //currentYear currentDateTime = DateTime.Now;    }

View Replies View Related

Date Select Question

 How can i select all users that have birthday today (or a specified day)?
profile table:
username - dobuser1 - 1983-08-21 00:00:00user2 - 1986-04-15user3 - 1985-11-04user4 - 1983-04-02
SELECT username, dob FROM profile WHERE (???)
Is it possible to do this?somehow ignore the year and match the day and month
The hour/minute/seconds are always 00:00:00

View Replies View Related

Copyrights 2005-15, All rights reserved