SQL DateTime and Searching for just the date portion

I have a SQL DB with a column called time_occurred that is formatted like ( 7/28/2004 7:10:30 AM ).

What I need to do is run a report based on just the month day and year portion. I am using the calendar control so mins, sec and milliseconds are not available nor do I really need them.
I am running the Query with this Stored Procedure

ALTER PROCEDURE dbo.Prodecure1
@WhereClause varchar(8000)

-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(8000)

-- Enter the dynamic SQL statement into the variable @SQLStatement
SELECT @SQLStatement = 'SELECT column1, column2, etc...' +

-- Execute the SQL statement
10/25/2004 5:02:49 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 50
Get it on Google Play
Get it on Apple App Store

run this in query analyzer:

select cast(convert(varchar(30), getdate(), 101) as datetime)

This trims off the time portion of a date and then returns it to a date format instead of text.

So, your where clause will be some variation of:

mydate >= cast(convert(varchar(30), @startdate, 101) as datetime)
mydate < dateadd(d, 1, cast(convert(varchar(30), @enddate, 101) as datetime))

So, if the user selected 10/25/04 thru 10/25/04 (today only), records in the database with mydate equal to anytime today would be selected regardless of the time portion of the date.
10/25/2004 7:46:51 PM

Similar Artilces:

.NET DateTime and SQL Server DateTime problem
.NET DateTime and SQL Server DateTime problem  I have the following if statement in an SQL stored procedure: IF (@Image = 1 AND @DateTimeUploaded = (SELECT ImageMainDateTime FROM Images WHERE UserID = @UserID))   The value of the @DateTimeUpdated variable was taken from the ImageMainDateTime field when the data was requested by a ASP.NET webpage and is passed back here when that page is submitted so I can compare what the DateTime was when the data was requested with what it is now, in other words I’m doing a concurrency check (I can’t use TimeStamp for many reasons, ...

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

Getting just the date from a "datetime" sql column along with other data of different formats
Hi. I have a web page that gets the current user, then goes into a database and gets a list of invoices, this includes: invoice numbers, the date of the invoice, the date the invoice was paid, and the amount of the invoice. The data is then bound to a repeater control and displayed. i need a way to get just the date and not the date and time from the datetime columns. Here is my code that i have now: This next part gets the current user, then creates the selection string and binds the repeater to the data.Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ...

Dealing with datetime and SQL Transact-SQL
I am trying to make a stored procedure in SQLServer Express.The question is related to this stored procedure / transact - sql.  I think i am doing something wrong with datetime.Here is the stored procedure.The error i am getting is that:Msg 241, Level 16, State 1, Line 20Syntax error converting datetime from character string.  ===================================== DECLARE    @websiteID  intDECLARE    @dateFrom  datetimeDECLARE    @dateTo  datetimeDECLARE    @sortbystring  varchar (20)set @websiteID...

Convert .NET DateTime format to SQL DateTime format
Hi!!I'd like to know if there is a function to convert the DateTime format used in C# (VS2005) : dd/mm/yyyy HH:mm:ss to the format used in SQL Databases: yyyymmdd HH:mm:ssThanks folks!...

Search a date range using a date range in sql server 2005
Hi guys, I have a query where i need to search certains dates to see if specific equipment is available for those dates. Problem is that i need to do this as a date range (both for the dates to find & the dates to find against). EG. I have a table which hold equipment booking & has a field called 'required Date' & 'Estimated return Date'. This is what the user specifies in order to book out a piece of equipment. If i had  laptop1booked out with a required date of 1/1/2008 & Estimated return date of 5/1/2008 then this laptop should not be available for ...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

convert an sql datetime column to .net datetime data type in front end...?
I have a field (ldate) in a table that typically displays data in the following format:2007-11-12 20:30:47.000In the front end I want the time and the date separately. But as I try to cast it to a datetime object it is giving me a System.NullReferenceException. What I tried to do was just this: Protected Sub gvTopics_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTopics.RowDataBound Dim img As Image = gvTopics.FindControl("imgIcon") Dim lbDate, lbTime As Label lbDate = gvTopics.FindControl(...

SQL Express to SQL ?
I am developing a site using the express edition of all tools (VWD and SQL Express).  I want to use GoDaddy hosting and was wondering if I will be able to effectively put my SQL database and website up on their hosting even though it was developed via Express edition of Microsoft programs?...

Compiled sql CommandText going from DataSource to sql server
HiI need to know what command text goes to sql server in a compiled (parameterless) formatEx :I have a sql query : "Select  * from table where name=@name"name parameter has value = "bill gates"When I read the e.command.commandtext value in sqldatasource.inserting event, it gives the original command (with parameter @name)In datasource.inserting event, how can I get the compiled version of the command  : "Select * from table where name='bill gates'"please help me Why do you need to get the value?  What do you plan to do with it?Brian"Trust in the Lord and do what is good...

SQL A and SQL Server
Hi I heard SQL Server used to be owned by Watcom is this true? Is SQL Anywhere, therefore, similar to SQL Server? -- Regards, John Not quite true. SQL Anywhere was created by Watcom. SQLServer was created by Sybase, and Microsoft licensed the technology. So MSSQL and ASE have common roots, not SQLAnywhere. -- Paul Horan[TeamSybase] "John Kingan" <john.kingan@abibuildingdata.com> wrote in message news:40d82aa1$1@forums-1-dub... > Hi I heard SQL Server used to be owned by Watcom is this true? Is SQL > Anywhere, therefore, similar to SQL Ser...

Inserting Date ONLY from SQL DateTime
with an SQL Database the DateTime data type will insert both date and time, however i have a formview with a textbox for inserting a date. i want to be able to only insert the data so that on other pages where the page must search through the database for relevant dates that it wont have a problem because the field has more values (that being the time). How do i get it to insert ONLY a date. it must be a date and not anything like char(11) as it needs to be validated and searched (unless someone can tell me how to search a database for records between dates thats fields are not dates).I dont...

Migrating dates from SQL Anywhere to MS SQL Server
I have just tried do add MS SQL Server 7 to the list of the databases supported by my PB/SQL Anywhere application and here is my problem: What do I have to do in MS SQL 7 to be able to use the SQL Anywhere 'date' data type? I don't want to rewrite my app and convert all dates to the datetimes because I have hundreds of them on literally hundreds of datawindows. SQL Anywhere has the 'date' data type. MS SQL 7 has 'datetime' which corresponds to the 'date' but you cannot just create a MS SQL user-defined 'date' type and map it t...

I have a problem, my asp.net page wants to connect to the sql server, but it has to be the mysql. How can I solve this problem? This is my code: <%@ page explicit="true" language="VB" debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.Odbc" %> <%@ Import Namespace="System.Data.SqlClient" %> <html> <script runat="server"> sub page_load(sender as object, e as eventargs) If Not IsPostBack Then dim connect as sqlconnectio...

Web resources about - SQL DateTime and Searching for just the date portion - asp.net.sql-datasource

String searching algorithm - Wikipedia, the free encyclopedia
In computer science , string searching algorithms , sometimes called string matching algorithms , are an important class of string algorithms ...

Facebook Becoming A Powerful Job Searching Tool
When most people think of a social media site that’s tailored to job searching and recruitment, the obvious answer seems to be LinkedIn . However, ...

Facebook Searching For Ways to Break Into Mobile Apps
Today’s mobile panel at the Facebook f8 developer conference was notable for the subject it didn’t cover: Facebook itself. With four panelists ...

Yahoo Video Guide - From searching to streaming in seconds! on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about Yahoo Video Guide - From searching to streaming in seconds!. Download ...

Searching Twitter With Google - Flickr - Photo Sharing!
See What Is Real Time Search? Definitions & Players. Feel free to use this image. Just link to the photo page or the story.

While searching for daughter, Va. girl's parents work to help others - YouTube
Washington Post While searching for daughter, Va. girl's parents work to help others Three months and three days. Thats how long it has been ...

Police searching Willunga property of Dale McCauley, who disappeared in 1998 and is believed to have ...
POLICE are searching a Willunga house, and a dam at a nearby property, over the disappearance and suspected murder of a man 17 years ago.

Microsoft left searching for answers as Google maps out market gains
Microsoft left searching for answers as Google maps out market gains

Big Bash League: Dick Smith collapse leaves Melbourne Stars searching for replacement key sponsor
Melbourne Stars' tumultuous week is on the cusp of returning to positive territory, with the Big Bash League team closing in on what would be ...

Searching ‘bubble level’ in Google Search now presents you with an interactive level
One Googler took to Reddit last week to tell the world about a new feature that his team (presumably) added to Google search. Now, if you search ...

Resources last updated: 1/17/2016 10:21:33 AM