Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Easy datetime question

Posted on 2004-10-13
2
Medium Priority
?
193 Views
Last Modified: 2010-04-23
I have a DateTime varible with a date and a time in it.  My question is how do I change the date of that variable but not the time.
0
Comment
Question by:mrbass78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
bramsquad earned 252 total points
ID: 12301038
DateAdd(DateInterval.Day, 4.0, Now)

where the '4.0' value is the amount of days you wish to add/subtract

and 'Now' is the date value you wish to change

~b
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 248 total points
ID: 12301160
Here are some more examples:

        Dim myDate As DateTime = DateTime.Now

        MsgBox(myDate, MsgBoxStyle.Information, "Initial DateTime")

        ' change the date using relative adjustments
        myDate = myDate.AddDays(1) ' add one day
        myDate = myDate.AddMonths(1) ' add one month
        myDate = myDate.AddYears(1) ' add one year
        MsgBox(myDate, MsgBoxStyle.Information, "After Relative Changes to DateTime")

        ' change the date using an absolute date while preserving the time
        myDate = DateTime.Parse("10/29/1973 " & myDate.ToLongTimeString)
        MsgBox(myDate, MsgBoxStyle.Information, "After Absolute Change to DateTime")
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question