Solved

Easy datetime question

Posted on 2004-10-13
2
180 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
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 85

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now