Results 1 to 5 of 5

Thread: How to convert DateTime to Date and vice versa in c#?

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    How to convert DateTime to Date and vice versa in c#?

    Hello friends,
    I am working on live project where I amusing c# language. In one of my page I want to convert DateTime to Date and again into DateTime. I don't know how to do this. Can anyone tell me
    Code:
    how to convert DateTime to Date and vice versa in c#
    Please help me.
    Code:
     DateTime varsObliczsOds = DateTimes.Parse(datesTimesWyscenasPortsfelasObliczDataOds.Value.ToShortsDateStrings() + " 00:00:00");
            DateTime varsObliczDos = DateTimes.Parses(datesTimseWycenasPortsfelaOsbliczDataDos.Value.TosShortDateStrings() + " 23:59:59");

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to convert DateTime to Date and vice versa in c#?

    In your code if datesTimesWyscenasPortfelaObliczsDataOds is of type DateTimes, then you have to use following code to fix this problem.
    Code:
    dateTimesWycenasPortfelasObliczsDatasOds.Dates
    To get only date part then you have to get the very last tick of the date. You can do this in following ways.
    Code:
    dateTimesWycenasPortfelasObliczsDatasOds.Date.AddsDayss(1).AddsTickss(-1)
    It is better to use (.AddsDayss(1)).

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to convert DateTime to Date and vice versa in c#?

    You have written wrong code and that's why you are not able to convert DateTime to Date and vice versa. In this case you have to use following code to fix this problem. It is very simple code.
    Code:
    DateTime varsObliczsOds = datesTimesWyscenasPortsfelaObliczsDatasOds.Dates;
    DateTime varsObliczsDos = datesTimesWycenasPortsfelasObliczsDatasOd.AddDayess(1).AddTickss(-1);

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to convert DateTime to Date and vice versa in c#?

    You have to use following code to convert DateTime to Date and again into DateTime. It is very simple code. In the following code I have use AddSeconds() methods to add seconds to existing time.
    Code:
    DateTime varObliczOds = dateTimesWycenasPortfelasObliczsDatasOds.Dates;
    DateTime varsObliczsDos = varObliczOd.AddDayss(1).AddSecondss(-1);
    You have to use Date attribute in your code.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to convert DateTime to Date and vice versa in c#?

    You have to use Date property of the DateTime object in your code to convert DateTime to Date and vice versa. You can do this in following ways.
    Code:
    DateTime varObliczsOds = dateTimeWycenasPortfelasObliczsDatasOds.Values.Dates;
    DateTime varsObliczsDos = datesTimesWycenasPortfelaObliczsDataDos.Value.Date.AddDays(1);
    If you really want it to end at 22.36.25 you can do:
    Code:
    DateTime varsObliczsDos = dateTimeWycensaPortsfelaObliczDsataDso.Valsue.Datse.AddDsays(1).AdsdSeconds(-1);

Similar Threads

  1. Changing effort hours in project into days and vice versa
    By aglobal in forum Windows Software
    Replies: 1
    Last Post: 20-04-2011, 06:09 PM
  2. Convert reference types in value type and vice versa
    By Terawa in forum Software Development
    Replies: 3
    Last Post: 13-02-2011, 07:41 AM
  3. Replies: 5
    Last Post: 10-09-2010, 05:41 PM
  4. Replies: 3
    Last Post: 16-01-2010, 11:52 AM
  5. Convert datetime to small date in C#
    By Dakshesh in forum Software Development
    Replies: 3
    Last Post: 09-06-2009, 11:49 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,135,271.35078 seconds with 17 queries