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.
1/4/2007 8:03:14 AM 91979 articles. 4 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 33

You can use one of the appropriate Standard DateTime Format Strings such as d or D.

Darrell Norton, MVP
Darrell Norton's Blog

Please mark this post as answered if it helped you!
1/4/2007 1:58:57 PM

You should be able to use

DateTime dt = DateTime.Now

dt.ToString("d")  //this will format as short date time

1/4/2007 2:05:03 PM
FYI: If you want to do it at the query level, for databinding purposes, etc. you can also use

SELECT CONVERT(varchar(10), datefield, 101) AS DateField FROM Table
1/4/2007 2:22:17 PM

If you are using a GridView, you can set the DataFormatString to "{0:d}". Then you need to set the HtmlEncode value to "False" on that column.

If you are setting the date/time value to a string, you can use the format: string shortDate = DateTime.Now.ToShortDateString();

Check out my new blog at
1/4/2007 2:32:03 PM
Iam using a Detailsview and field is a template field. What i realised is that the DateFormatString property disappears once a filed is tuned to a template field. With non Template fields "{0:d}" on DateFormatstring works.  
No Project Too Eazy.
1/5/2007 6:14:53 AM


 You should be able to do something like: 


1    <ItemTemplate> 
2          <asp:Label ID="BirthDateLabel" Runat="Server" 
3                     Text='<%# Eval("BirthDate", "{0:d}") %>' />
4        </ItemTemplate>


Hope this helps

Dennis J. Bottjer
SpringPoint |
DrowningInTechnicalDebt | Blog
1/5/2007 6:57:55 AM

You can also do

    <asp:Label ID="BirthDateLabel" runat="server" Text='<%# Convert.ToDateTime(Eval("BirthDate")).ToShortDateString() %>' />


Mark post(s) as "Answer" that helped you

Electronic Screw
1/5/2007 9:26:02 AM

 If your not using a Template field you can use...


<asp:BoundField DataField="AppointmentDate" HeaderText="AppointmentDate" SortExpression="AppointmentDate" DataFormatString="{0:d}" />
7/23/2008 6:49:05 PM

Similar Artilces:

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 /...

Date / Time Field
PB 7.0.3 I have an application that records patient encounters, treatments and referrals for an Emergency Department within a hospital. Each encounter records time to nurse and time to physician - these fields are of datetime format. This application is for statistical purposes only and therefore is not real time (unit clerks key in the necessary data throughout the day). Here is a senerio... Patient A enters the ED and the date / time of encounter is recorded. The date and time that the triage nurse first assesses the patient is recorded (time to nurse) The date and time that th...

How to remove the date part of a Date/Time value in MS Access
I am inserting a time value into a MS Access Date/Time field and notice that MS Access does not display the date portion of the value but when I look at the same data in my programming using a TADOTable component I am seeing the date of 12/30/1899 in conjunction with my time value. I read that Access is handling this within MS Access so that when a 0.sometime value is inserted it does not display the date. How do I handle this within my Delphi program so that I can display the time only in a Date/Time type field? Jeff Howard wrote: > I am inserting a time value into a MS Access Date/T...

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,I have a column on a GridView that is formatted to only display the time part of a date time field. However, whenever I edit the cell value the Date part of the field is changed to today's date. The way I've got round this is to implement the CellValueChanged event. Is there a better way of doing this? Code is below. private void dgTimeSlots_CellValueChanged(object sender, DataGridViewCellEventArgs e) { int col = e.ColumnIndex; int row = e.RowIndex; if (col >= 0 && row >= 0) { // the correct date ...

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...

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...

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...

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 ...

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 field field value at specified date and time....
I am doing one project in that...... after login user set one date and will store in one sql table.......... now user logout from the page also website ..... but now i want to update one field value to 1 but on specified date and time which was entered by user so many days ago..... Please help....... i know the code to update sql table but where to write that code(fire on that particular date and time) and  that i dont know..........Mayursinh B Rana9898010015Marking a Reply as 'Answered', not only GAIN us some POINTS, but it also HELP others ...

Date Time field return just time
 Hi, I have a data/time field in access which is queried using a datasource linked to a check box list, the field contains only hh:mm but is returning dd/mm/yyyy hh:mm, does anyone know how to just return hh:mm? Thanks  Hi, It will return complete date and timestamp so if you want the same to be displayed in hh:mm format then while qerying you will need to format the feild if you want it in hh:mm.  ThanksAshish

Remove the time part from a date
Hello, I have a datatable with a column of dates and times -  xx/xx/xxxx 12:00:00 AM I want to remove the12:00:00 AM Below is two For next loops I tryed with no luck.  I even tryed to cast the listitem.text to a date and it still didn't  work. Thanks Steve Dim i As Integer = 0 For i = 0 To ds.Tables(0).Rows.Count - 1 Dim li As ListItem = ds.Tables(0).Rows(i).Item(0) Format(li.Text, "MM/dd/yyyy") Next   Dim i As Integer = 0 For i = 0 To ds.Tables(0).Rows.Count - 1 Dim li As ListItem = ds.Tables(0).Rows(i).Item(0) Microsoft.VisualBasic.Left(li.Text, 10) Next...

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" You can use variouos formatting options to present the date in format you want. Can you post your grid declaration...

Web resources about - remove time part from a date/time field value -

ADL To Facebook: Remove Jewish Ritual Murder Page
... again found itself in the “damned if you do, damned if you don’t” conundrum caused by controversial subject matter , being pressured to remove ...

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

Now Users Can Remove Contacts Automatically Saved by Facebook’s Friend Finder
Two weeks ago, many Facebook users began asking questions about curiously good recommendations suddenly appearing in Facebook’s “People You May ...

Mac App Store - Focus • Remove Distractions and Get More Done
Get Focus • Remove Distractions and Get More Done on the Mac App Store. See screenshots and ratings, and read customer reviews.

Queensland police remove 14 alleged rioters from Aurukun - The Courier-Mail Search Search
FOURTEEN men who allegedly led days of rioting in Aurukun were flown into Cairns under police guard last night.

Police remove 14 alleged rioters from Qld town
FOURTEEN men who allegedly led days of rioting in Aurukun were flown into Cairns under police guard last night.

Coles, Woolworths pledge to remove products containing plastic microbeads
Coles and Woolworths pledge to remove products containing tiny plastic particles called microbeads in Australia

Ohio Removes Question About Driver's Licenses From Job Form
Ohio has removed the question asking job applicants if they have a driver's license from the state's online hiring system.

Twitter’s reported plans to remove Twitter’s defining feature are terrible
Some dude named Shakespeare once wrote: brevity is the soul of tweet. Smart fellow. The 140-character limit is not merely some incidental feature ...

Here's how to remove all Donald Trump references when you're online
... from based on your mood. You can even choose to keep him off just one frequently visited website, in case you don't want to totally remove The ...

Resources last updated: 1/10/2016 10:02:46 AM