Solved

Easy datetime question

Posted on 2004-10-13
2
191 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 63 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 62 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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