Setting Time or Date Portions of a Date data type

K

Kevin Buchan

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
(e-mail address removed)
 
M

Manoj G [MVP]

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

Kevin Buchan

<blech>

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

Thanks for the reply.


-Kevin Buchan
(e-mail address removed)


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.

message
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top