Setting Time or Date Portions of a Date data type

Discussion in 'ASP .Net' started by Kevin Buchan, Nov 13, 2003.

  1. Kevin Buchan

    Kevin Buchan Guest

    In VB6, if I had a Date data type with either the date or the time
    being something I wanted to keep and I wanted to replace the other
    part of the value (like changing the date to 'tomorrow, same time') I
    would Format() the Date variable as a string with just the part I
    wanted to keep, concatenate that with the new value, then CDate() it
    back into a date.

    With JScript, I can call setTime() and setDate() to accomplish the
    same thing, with much more readable code.

    What is the 'right' way to do this with the .Net Framework's
    System.DateTime data type?

    Thanks.


    -Kevin Buchan
     
    Kevin Buchan, Nov 13, 2003
    #1
    1. Advertising

  2. HI,

    You can call upon the AddMinutes, Addhours, AddDays and a host of other
    related methods on a DateTime instance to do the same. The values you add
    can also be -ve too.

    --
    HTH,
    Manoj G [.NET MVP]
    http://www15.brinkster.com/manoj4dotnet

    "Kevin Buchan" <> wrote in message
    news:...
    > In VB6, if I had a Date data type with either the date or the time
    > being something I wanted to keep and I wanted to replace the other
    > part of the value (like changing the date to 'tomorrow, same time') I
    > would Format() the Date variable as a string with just the part I
    > wanted to keep, concatenate that with the new value, then CDate() it
    > back into a date.
    >
    > With JScript, I can call setTime() and setDate() to accomplish the
    > same thing, with much more readable code.
    >
    > What is the 'right' way to do this with the .Net Framework's
    > System.DateTime data type?
    >
    > Thanks.
    >
    >
    > -Kevin Buchan
    >
     
    Manoj G [MVP], Nov 16, 2003
    #2
    1. Advertising

  3. Kevin Buchan

    Kevin Buchan Guest

    <blech>

    I really hoped for a single method call rather than three.

    Thanks for the reply.


    -Kevin Buchan



    On Sun, 16 Nov 2003 14:17:24 +0530, "Manoj G [MVP]"
    <> wrote:

    >HI,
    >
    >You can call upon the AddMinutes, Addhours, AddDays and a host of other
    >related methods on a DateTime instance to do the same. The values you add
    >can also be -ve too.


    "Kevin Buchan" <> wrote in
    message
    news:...
    > In VB6, if I had a Date data type with either the date or the time
    > being something I wanted to keep and I wanted to replace the other
    > part of the value (like changing the date to 'tomorrow, same time') I
    > would Format() the Date variable as a string with just the part I
    > wanted to keep, concatenate that with the new value, then CDate() it
    > back into a date.
    >
    > With JScript, I can call setTime() and setDate() to accomplish the
    > same thing, with much more readable code.
    >
    > What is the 'right' way to do this with the .Net Framework's
    > System.DateTime data type?
    >
    > Thanks.
    >
    >
    > -Kevin Buchan
    >
     
    Kevin Buchan, Dec 1, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian H
    Replies:
    0
    Views:
    298
    Christian H
    Aug 8, 2003
  2. ani
    Replies:
    7
    Views:
    2,113
    Alphonse Giambrone
    Jan 5, 2004
  3. Jeremy Chapman

    Reading portions of the web.config file

    Jeremy Chapman, Jun 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    406
    John Timney \(ASP.NET MVP\)
    Jun 22, 2005
  4. Nadie
    Replies:
    1
    Views:
    329
    Bengt Richter
    Aug 16, 2005
  5. Replies:
    1
    Views:
    286
    Kent Johnson
    May 22, 2006
Loading...

Share This Page