Remove time from Date field

Hi, I have a datagrid that displays results from a stored procedure. It contains a date column that displays the entered date of the record. This is not a time stamp field and the value stored in the database is just the date. When I run the procedure and fill the datagrid, the column values look like this.

2005-04-06 00:00:00

Does anyone know how to prevent that? Any help would be appreciated. Thanks!

"Worry not that no one knows of you, seek to be worth knowing"
4/13/2005 2:45:58 AM 72751 articles. 3 followers. Follow

12 Replies

Similar Articles

[PageSpeed] 40

You can use variouos formatting options to present the date in format
you want. Can you post your grid declaration here and i'll give you an
example of that. (if you are using Autogenerated columns then you'll
have to write some code to do the formatting, otherwise it is just a
formatting specified in your html page)


Bug [MCSD]
4/13/2005 8:36:46 AM

If your project is SQLserver-based,you can modify some statement in your store procedure.For examle:

select id,YourName,YourDate from tblYourTable.


select id ,YourName,(cast(DATEPART(year,YourDate ) as varchar(4))+'-'+cast(DATEPART(month,YourDate ) as varchar(2))+'-'+cast(DATEPART(day,YourDate ) as varchar(2)) as newDate from tblYourTable

if you merely want to display the datetime in the format that you want,that is enough.

4/13/2005 10:02:35 AM


if you are using sql server databse.

this will works for you


Junior Programmer,
4/13/2005 1:48:48 PM
If you want to manipulate it in your code, try:


'Old and wrinkled is not what I expected to become when I grew up!'
4/13/2005 2:21:36 PM

The project is SQL server based. The results are returned to a datagrid via a stored procedure. Here is my code behind.

Dim workparam3 As New SqlParameter("@StartDate", System.Data.SqlDbType.DateTime)
        workparam3.Direction = ParameterDirection.Input
        workparam3.Value = (Calendar1.SelectedDate)

        Dim workparam4 As New SqlParameter("@EndDate", System.Data.SqlDbType.DateTime)
        workparam4.Direction = ParameterDirection.Input
        workparam4.Value = (Calendar2.SelectedDate)

        Dim workparam5 As New SqlParameter("@UserID", System.Data.SqlDbType.VarChar)
        workparam5.Direction = ParameterDirection.Input
        workparam5.Value = (User.Identity.Name)

        Dim ds As DataSet

        Dim daRGU As New SqlDataAdapter
        daRGU.SelectCommand = New SqlCommand
        daRGU.SelectCommand.Connection = SqlConnection1
        daRGU.SelectCommand.CommandText = "AgentRGUTotal"
        daRGU.SelectCommand.CommandType = CommandType.StoredProcedure

        ds = New DataSet
        Catch ex As Exception
            dgRGU.DataSource = ds
        End Try

Since I'm just passing parameters to a stored proc, I don't think I can change the format here. I think I have to do it in the proc but I'm not sure. Here is the procedure.

CREATE PROCEDURE [ServiceTypeTotals]

@StartDate [DateTime],
@EndDate [DateTime],
@UserId [VarChar] (50)


Select Account, EnterDate,
Sum(BasicIns) As "Basic", Sum(ExpBasIns) As "Expanded Basic", Sum(BasDigIns) As "Basic Digital", Sum(BigIns) As "Big",
Sum(BiggerIns) As "Bigger", Sum(BiggestIns) As "Biggest", Sum([384Ins]) As "384Kbps", Sum([3MbIns]) As "3Mbps", Sum(NetIns) As "Home Networking",
Sum(FSecIns) As "F Secure", Sum(WMIns) As "Wire Maintenance", Sum(EFTSIns) As "EFTS", Sum(HDCombIns) As "HD/DVR Combo", Sum(HDIns) As "High Definition",
Sum(HDTierIns) As "High Def Tier", Sum(DVRIns) As "DVR", Sum(SVODIns) As "SVOD", Sum(FamIns) As "Family Tier", Sum(BigMIns) As "Big Movie Tier",
Sum(LatIns) As "Latino Tier", Sum(SpoIns) As "Sports Tier", Sum(HBOIns) As "HBO", Sum(StarzIns) As "Starz", Sum(SelfIn) As "Self Install",

Sum(BasUp) As "Basic Up", Sum(ExpBasUp) As "Expanded Basic Up", Sum(BasDigUp) As "Basic Digital Up", Sum(BigUp) As "Big Up",
Sum(BiggerUp) As "Bigger Up", Sum(BiggestUp) As "Biggest Up", Sum([384Up]) As "384Kbps Up", Sum([3MbUp]) As "3Mbps Up", Sum(NetUp) As "Home Networking Up",
Sum(FSecUp) As "F Secure Up", Sum(WMUp) As "Wire Maintenance Up", Sum(EFTSUp) As "EFTS Up", Sum(HDCombUp) As "HD/DVR Combo Up", Sum(HDUp) As "High Definition Up",
Sum(HDTierUp) As "High Def Tier Up", Sum(DVRUp) As "DVR Up", Sum(SVODUp) As "SVOD Up", Sum(FamUp) As "Family Tier Up", Sum(BigMUp) As "Big Movie Tier Up",
Sum(LatUp) As "Latino Tier Up", Sum(SpoUp) As "Sports Tier Up", Sum(HBOUp) As "HBO Up", Sum(StarzUp) As "Starz Up", Sum(SelfUp) As "Self Install Up"

From bss_SalesTracker

Where (EnterDate Between @StartDate AND @EndDate) AND UserId = @UserId

Group By EnterDate, Account

Thanks for the help everyone!!! Big Smile [:D]


"Worry not that no one knows of you, seek to be worth knowing"
4/14/2005 2:53:12 PM


If you want to store only Date(not the time) in the SQL server Database you cannot do by choosing DateTime or SmallDateTime Datatypes as they take default time if are not supplying the time.

So if u do like the above thing i.e only date , declare the datatype as varchar and cast the date to string and store.


Junior Programmer,
4/14/2005 4:28:53 PM

Will I still be able to query based on date parameters set from a calendar component? And do I change the format in SQL or the asp form? Thanks!

"Worry not that no one knows of you, seek to be worth knowing"
4/14/2005 4:47:04 PM
Your issues are all related to formatting the date which clearly is a
presentation layer related one. So i'd suggest you to format the date
only at display time and leave the sql intact. This way you will not
run into extra trouble if later you'll decide to perform some date
manipulations in your business layer. If you want to use the value
extracted from the page to perform the database query in addition to
showing the date, i'd suggest you create a couple of function - one
that formats the date variable to be shown on a page and another - to
do the reverse - convert the stirng into string. This way you would
keep all the logic together and would greatly improve the code
maintanance etc


Bug [MCSD]
4/14/2005 5:19:42 PM

As bug pointed out ( and he is seldom, almost never wrong Smile [:)]), just modify the date at presentation level, with the date being displayed as a short date or any other format.



4/14/2005 8:48:26 PM
Thanks  for the comment, feels good to hear things like that :D
Bug [MCSD]
4/15/2005 8:38:46 AM
Awesome! Thanks for the help guys. I'll check out the link Big Smile [:D]
"Worry not that no one knows of you, seek to be worth knowing"
4/16/2005 4:28:41 AM

I have used this in my, c# source code for initializing the SqlDataSource of my DataGrid. It works fine for me :)

select (cast(DATEPART(year,YourDate ) as varchar(4))+'-'+cast(DATEPART(month,YourDate ) as varchar(2))+'-'+cast(DATEPART(day,YourDate ) as varchar(2)) as newDate from tblYourTable


Amat Victoria Curam
6/30/2005 3:03:36 PM

Similar Artilces:

remove time part from a date/time field value
How does one remove or avoid the time part from a date/time field value. For example store 12/12/2006 instead of 12/12/2006 12:00:00 Am --------------------------------------------------No Project Too Eazy.-------------------------------------------------- You can use one of the appropriate Standard DateTime Format Strings such as d or D.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! You should be able to use DateTime dt = DateTime.Now dt.ToString("d")  //this will format as short date time FYI: If you want to do it at the query ...

just Time or date portion of a date/time field
Good Day, From a DateTime data column how do I get just a Time portin or just a date portion of data to be displayed. i.e from 11/6/2003 10:03:20 AM I need to display date and time seperately in my data display page. Thanks Regards, In code you could use Dim dt as System.Date Dim day, month, year as integer day = dt.Day month= dt.Month year = dt.Year This also works with DateTime In SQL you could use DATEPART(<datepart>,<datetime>) where <datepart> is the abbreviations mentioned in post 385301 and <datetime> is a...

Remove Time portion of date field
Good Day Folks, I'm displaying a date field from an Oracle table in a datagrid with the following template. <ItemTemplate> <asp:Label id="hiredate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"hiredate","{0:d}") %>'> </asp:Label> </ItemTemplate> Does anyone know which date/time formatting string would remove the time portion of the field ? Thanks in advance /serge/Serge I would suggest you to get only data while getting from ORacle Data ...

Date entered...add time value to make date/time field
Windows XP Professional InfoMaker v 9.0.2 Build 7509 Our database contains a date/time stamp for when a specific activity happens to each shipment. I would like the users to be able to simply enter a date for a specific work day. I need to get a list of shipments where the time of one activity occurred on the entered date prior to 9:20. How can I create a computed field that will basically concatenate/amend the entered date with 9:20 that will later be used for criteria in returning rows? Thanks in advance for any help you can provide! Rita Palazzi Senior Engineer /...

just Time or date portion of date/time field: SOMEBODY PLS
Good Day, From a DateTime data column how do I get just a Time portin or just a date portion of data to be displayed. i.e from 11/6/2003 10:03:20 AM I need to display date and time seperately in my data display page. Thanks Regards, When you pull in a SQL datetime column value into your .NET code, it is usually cast to a .NET DateTime type... something like this: System.DateTime TheDateAndTime = (System.DateTime)someDataReader["MySQLDateColumn"] Then you can use a variety of .NET methods included in the DateTime class to convert to a strin...

Removing Time from date time
We would like to form a recordset that would have the datetime column be just the date. We have students visiting our web several times a day and each of these are counted as distinct dates. We would like just the total number of days that they used the web not the total number of times they accessed the web. Thanks Jim You can use date function on datetime column, or use cast. eg: select datetime_col, date(datetime_col), cast(datetime_col as date) from some_table Hope this helps, Goran jmwarren wrote in message <>... >We would li...

Hello, If the field is defined as a DATE and you do: select datefield+1 from mytable Does the ODBC API (actually ASA 9.02 backend) return a field that is DATETIME or a DATE field? It is messing up my compiled application and seems to be coming back as DATETIME. Thank you. -Robert You are correct, the value is being returned as a TIMESTAMP. You can verify this through using the EXPRTYPE() builtin function, as in select exprtype('select datefield+1 from mytable', 1) from dummy which will return TIMESTAMP. Exprtype is documented in the help. You alm...

.net 2
Hi Friends, I am using .net 2.0 and developing a Web Site. I have to give selection of Date and Selection of Time for some searching facility. Do we have any such Date Time picker control in .net 2.0 ? Like when user clicks it, it opens up a calender to select a date, or user can also type date into it, and same for Time. Thanks in advance, Nirav No, but you could use a 3rd party control like Peter's Date Package.RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

date/time or date and time
I am setting up an SQL database and I will need to get differences in dates. For example I have a start date, start time, completion date and completion time and I want to get the difference between the start and completion. Would it be better to have one field with both date and time in it, or better to have a date field and a time field? Even though I have already started setting up the tables with seperate fields for date and time I am now leaning toward one field with date/time in it. (Only because that is the way I had to do it when setting up an Excel spreadsheet for a similar ta...

hide time in date/time field
hi. i have code : objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\database\tfasim.mdb;")   if rblLTorGT.SelectedValue = "Id" then      strSQLQuery = "SELECT Date_T as  [date] ,name FROM table " & _     ORDER BY " & ddlSortBy.SelectedItem.Value.ToString() & ddlSortOrder.SelectedItem.Value.ToString()   objCommand = New OleDbCommand(strSQLQuery, objConnection)   objConnection.Open()    objData...

Update Only the Time in a date time field
Hi,i have a table having a datatime field and on a datagrid I need only to display and update the time part. I'm using select CONVERT(CHAR(8), JobStartTime, 8) AS StartTime from table to get the date. What is  the best way to write the update command . What woul dbe the best approch.   Regards, Vijay  1. Instate of doing formatting in the SQL, Try to do that is the DataGrid with FormatString. 2. To Update the Database , you can do that in two ways.    a. Either go for Store Procudure. Send the TIME you want to set for record. Your SP should some ...

Validate date field, and time field
I've got a form with 2 textboxes 1 for a date, the validator needs to check if he has this kind of imput: dd-MM-yyyy1 for the time, this one needs to check if he has this kind of imput: MM:HH But how can i do that?  You can either write a custom validator or you can use the AjaxControlToolkit MaskedEdit control: I just used them in my last project and they did the job they needed to. I was a bit reserved about the way it works when you replace characters but I decided in normal use this wouldn...

Date field showing date and time
Hey all, I have a datagrid that gets a date but shows the time as well. How do I show only the date? In the database only the date shows up. Thanks in advance, Rodney Hi Rodney, This is a very good date and time formatting article. Hope this helps U. Thanks!Regards, Dj Dev Here's how I do it: <asp:TemplateColumn HeaderText="Required Date"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "ReqDate", "{0:MM/dd/yyyy}") %&...

Missing date in time/date field
Hi, I noticed that some postings (including mine) don't show the date, just the time of sending the message. What setting do I need to change to enable this? MegaMad - Leo MegaMad wrote: > Hi, > > I noticed that some postings (including mine) don't show the date, just > the time of sending the message. > > What setting do I need to change to enable this? > > MegaMad - Leo Any post sent today will only show the time, those same posts will show the date and time tomorrow. -- Brian .. .. http://ilias.c...

Web resources about - Remove time from Date field -

App Launching On Valentine’s Day Allows Users To Remove All Traces Of Exes From Facebook Timelines
Just in time for Valentine’s Day — launching Thursday, in fact — comes mobile application KillSwitch , which allows users who are still Facebook ...

Platform Updates: New User Object fields, Edge.remove Event and More
New User Object fields, Edge.remove event, and more

Facebook updates iOS Pages Manager to improve speed, allow photo editing, but removes detailed post insights ...
Facebook released version 2.0 of its Pages Manager app for iOS on Wednesday, making it faster and including features like photo filters and stickers ...

App Store - Cleanup: remove multiple contacts fast
Get Cleanup: remove multiple contacts fast on the App Store. See screenshots and ratings, and read customer reviews.

Circus forced to remove illegal clowns from Fremantle homes
A circus troupe has been told to remove giant blow-up clowns and banners from dozens of Fremantle front yards because it did not get planning ...

Kimberley cops remove Facebook post bragging of 'granny' pot bust
Kimberley police have pulled down a Facebook post boasting of a 50-gram cannabis bust on a 57-year-old woman in Halls Creek, after a heated online ...

AFP removes passenger from Brisbane-bound Virgin flight in Melbourne
A male passenger on a Virgin Australia flight to Brisbane was escorted off the flight by the Australian Federal Police.

National police union asks NFL to remove stadium gun ban over Paris attacks
... States, wants more good guys with guns in football stadiums. In a letter to NFL commissioner Roger Goodell, they called on the league to remove ...

To make a thinner ‘iPhone 7,’ Apple could remove the headphone jack
... always, we’ll keep you posted with further information concerning the device as we receive it. To make a thinner ‘iPhone 7,’ Apple could remove ...

Donald Trump 'politely' removes protester from rally
Presidential candidate Donald Trump asks security to remove a protester from a rally in Sarasota, Florida.

Resources last updated: 12/3/2015 4:32:46 PM