Get date portion from DateTime (with DateTime property)

    private string _Date;
    public string Date
    {
        get { return _Date; }
        set { _Date = value; }
    }

objDados.Date = Convert.ToDateTime(drResult["APP_DATE"]).Date.ToString("dd/MM/yyyy");

If I replace _Date from string to DateTime, how can I get only date portion from DateTime? Thanks


Best regards,

Ivan Andrade
0
Roberot
9/12/2007 3:20:18 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

5 Replies
928 Views

Similar Articles

[PageSpeed] 29

Hi

 you could always copy it. But I'd put the Date property to be of DateTime type. Something like:

   private DateTime _Date;
    public DateTime Date
    {
        get { return _Date; }
        set { _Date = value; }
    }

DateTime dt = Convert.ToDateTime(drResult["APP_DATE"]);

objDados.Date = new DateTime(dt.Year, dt.Month, dt.Day);

DateTime instance itself always has time too, so for display you need to use string formatting (xxx.ToString("dd/MM/yyyy");) if you want to omit the time. And DateTime instance has all the methods you need.

 


Thanks,

Teemu Keiski
Finland, EU
0
joteke
9/12/2007 3:51:22 PM

It does not work

E.g. first row returned in datagrid displays: 12/9/2007 00:00:00

How to get only date portion? (without time)


Best regards,

Ivan Andrade
0
Roberot
9/12/2007 6:25:16 PM

If you are using C#, there is a built in method that extracts only the date from a DateTime object.  You could use something like this. 

// returns date string 
// ex. 9/12/2007 

objDados.Date = Convert.ToDateTime(drResult["APP_DATE"]).Date.ToShortDateString(); 

0
hungle
9/12/2007 8:24:34 PM
I need a solution using DateTime type.
Best regards,

Ivan Andrade
0
Roberot
9/13/2007 11:29:01 AM

Roberot:

It does not work

E.g. first row returned in datagrid displays: 12/9/2007 00:00:00

How to get only date portion? (without time)

Post the grid and also some relevant code so it's easier to help you.  String formatting is the clue but you haven't ptovided enough details. Are you perhaps using GridView with BoundField, remember to set HtmlEncode="false" to the BoundField if you do.

 


Thanks,

Teemu Keiski
Finland, EU
0
joteke
9/13/2007 3:14:49 PM
Reply:

Similar Artilces:

Get Date portion from Datetime
Hi all How to get just the date portion from a datetime field from sql server? thanks a lotBest regards,Ivan Andrade CONVERT(varchar,yourDateColumn,101)   Check out CONVERT function in BOL for more options.***********************Dinakar NethiLife is short. Enjoy it.*********************** Hi I'm getting a System.IndexOutOfRangeException error in resultset while(result.Read())    {    this.escritorios.codEscritorio = (int) result["Cod_escritorio"];    this.filiais.codFilial = (int) result["Cod_filial"];   &nb...

Parse DateTime into Date or select DateTime as Date from Access
I am getting DateTime values out of an Access Database and I want to only use the Date part of this field. I have tried to cast the returned value to a DateTime value and then format the DateTime to only show the Date part in the toString() fcn. <asp:Label runat="server" Text='<%# getDate(DataBinder.Eval(Container, "DataItem.ACTIVE_FROM"))%>'> But I can't cast the object to a DateTime object. I have also tried using DateTime.Parse() but this gives an error saying that the format is not correct.         {       ...

get only date from a date with a datetime format
i have a problem with dates when it comes to searchingbasically, SQL searches for a date including the seconds,but i only need to date so that in any given time, it will yield a result.here's a part of my code-behind code: reqNo = RequisitionsLogic.GetReqNoByDate(currentDate, requestorCode)and here's the SQL statement created in a TableAdapter:SELECT RequisitionNoFROM RequisitionsWHERE (RequisitionDate = @RequisitionDate) AND (RequestorCode = @RequestorCode) take a look with this, don't just accept influenceshttp://thedailyarr.tkhttp://www.ftpx.com/index...

Issue when converting XML dateTime to .NET DateTime
Hi, I am experiencing an issue when deserializing XML dateTime nodes in ASP.NET in some timezones. The construct 0001-01-01T00:00:00.0000000+ZZ:ZZ where ZZ:ZZ is the timezone offset for the timezone on the current system should produce a DateTime value equalling the constant DateTime.MinValue when converted. This works some of the time, such as for the Paris time offset of +1: (CDate("0001-01-01T00:00:00.0000000+01:00") = DateTime.MinValue) = True But does not work for Sydney time offset of +10: (CDate("0001-01-01T00:00:00.0000000+10:00") = DateTime....

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

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

Get Date Only from DateTime in GridView
Howdy Folks,I'm loading a GridView from an Access DataBase. I've been trying every thing I can come up with trying to figure out how to get the Date only from a GridView Field. I've used a TableAdapter/DataTable, AccessDataSource, and Custom SQL Statements to load the GridView. No matter what I do, the field always has "12:00:00 AM" attached to the Date.The Date is set to Short Date in the Access DataBase I used the following code which takes the field item and formats it to ShortDate, IF I put the result in a TextBox. But when I put it in the GridView the time is always attached.D...

As DateTime = DateTime.Now....
Hello: I have a process that runs and would like to preserve the computer time inside of the variable when the process finishes. Using this method Dim dtDateTimeVar As DateTime = DateTime.Now the information inside the variable does not stay static and keeps changing with the time... what can I do to work around this?Need ASP.NET web hosting? Private Message me for a free quote. I have even tried something like this... Dim dtDateTimeVar as DateTime = DateTime.Now Dim varOldTime as String varoldtime = dtDateTimeVar It still gets the current time instead of the...

Datetime to xsd:datetime
Dear all, i need to create a datetime variable with this format: "2003-02-04T13:58:59.9999999+03:00"? i need the variable in Datetime format not string format.. Thanks. Cisatlantic: Dear all, i need to create a datetime variable with this format: "2003-02-04T13:58:59.9999999+03:00"? i need the variable in Datetime format not string format.. Thanks. So what's the problem?  If you declare a variable as a datetime it will serialize in the above format automatically, and the calling objects will treat it as a date when it receives it. no problems, it worked, thanks...

How do I get the date part from datetime variable ?
How do I get the date part from datetime variable ? e.g declare @start_time datetime select @start_time = "10/31/2003" This puts date and current System time into the variable. I use this for some comparison on datetime field on database. But when I do the comparison, I want to do the comparison without time part on database field and my variable. How do I do that ? Thanks Check out the datepart function. In article <3fd10c0f$1@forums-1-dub>, <phari> says... > How do I get the date part from datetime variable ? > > e.g > declare...

Get DateTime form Access Database
Hi All, I have created an Access Database to control Selected Days from Calendar control. The user can type two Dates in two different Textboxes( Date from - Date to). With insert() method I can insert selected days in access database named "mydates". How can I get these Dates which are allready recorded in Database(mydates) and compare them with currently selected dates from another user? The goal is, that the following user should not be able to select the same date range, which has already been selected by a previous user. Any help will be highly appreciated! ...

get DateTime.Now.Date in sql
 Hi, Im making an c# asp.net website. I use an dataset and an gridview.  I will fill an gridview with users with the follow sql query:SELECT     UserIdFROM         StatsWHERE     LunchDate =  DateTime.Now.Date()How can I get all the users with the date of today?I have try the follow solution but it doesnt work:SELECT     UserId FROM         Stats WHERE     LunchDate =  @LunchDateIn the objectDataSource I hav...

getting just the date or from DateTime field
Hi, I have used smalldatetime datatype to store my date and time values. i want to store just the date or time but the problem is it stores both the date and time. For eg, if i add the the date 03/11/2004, it also the stores the current time automatically. so the new value will be something like 03/11/2004 10:00:00 AM where i want just 03/11/2004. further problem is even though i managed to store just the date like 03/11/2004 in the database, whole date and time shows up when i display it in my pages. any help will be appreciated. thanx,-keeara g------------------ If i want to dis...

Getting date and datetime system formats
Hi, How can I get the default date and datetime formats PowerBuilder uses for string conversion? Thanks in advance, Yves. I believe that PB checks the Windows regional settings and uses the values there. On Wed, 28 Feb 2001 11:18:16 +0100, in powersoft.public.powerbuilder.powerscript Yves Joosen <yves.joosen@be.xrtcerg.com> wrote: >Hi, > >How can I get the default date and datetime formats PowerBuilder uses for >string conversion? > >Thanks in advance, >Yves. > > Bruce Armstrong [TeamSybase] http://www.needhim.org ---== Po...

Web resources about - Get date portion from DateTime (with DateTime property) - asp.net.web-forms

Is there a JQuery plugin to convert UTC datetimes to local user timezone?
If I have a tag: &lt;span class="utctime"&gt;2010-01-01 11:30 PM&lt;/span&gt; I would like a jquery script or plug in to convert every utctime ...


Targetprocess 3.7.3: Epic unit for Bug/Story cards, new DateTime functions in Webhook plugin
Webhook plugin supports new DateTime functions AddDays(DateTime date, int days) – Returns a new date with the number of days added. The number ...

Common Pitfalls when working with DateTime’s
In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you ...

Parsing Twitter Date format to .Net DateTime
Recently when I needed to parse the twitter datetime format into a .Net DateTime I found this post on the web showing how to do it. However, ...

C Sharp (programming language) - Wikipedia, the free encyclopedia
(pronounced see sharp ) is a multi-paradigm programming language encompassing strong typing , imperative , declarative , functional , generic ...

1753 - Wikipedia, the free encyclopedia
Language: English Afrikaans አማርኛ العربية Aragonés Asturianu Aymar aru Azərbaycanca বাংলা Bân-lâm-gú Basa Banyumasan Беларуская ‪Беларуская (тарашкевіца)‬ ...

Coded Smorgasbord: Schizophrenic Haiku Comments and More
... writes Malcom StandardResponse UnSubscribeNewsletterUserAccount( string opTinGUID,string email, string sellingRegion, string source, DateTime ...

Limburg.be - Welkom op de site van de provincie Limburg - Welkom_op_de_site_van_de_provincie_Limburg
visit wonen werken leven ontspannen infopunt home op trefwoord contactpersonen wegwijs sitemap print deze pagina Je bent hier: limburg.be Contact ...

Simples Ideias. Por Nando Vieira.
Simples Ideias Siga-me no Twitter Junho/2012 Usando o Vagrant como ambiente de desenvolvimento no Windows http://simplesideias.com.br/usando ...

Resources last updated: 1/1/2016 4:22:53 PM