Click here to Skip to main content
15,918,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in vb.net how is to change date and time values i mean like this:
for example: today is: date1 = system.datetime.today,.....

if x=1 then
date1 += 1(?this is the part i want to know?)
date2 plus 4 hours
date3 plus 2 days and 12 hours
date4 minus 1 day and 2 hours
end if

or it doesn't work like this and i should work with timers to tick in specified time?
as a matter of fact i'm using this in a connection to MS access database, and i want to change the times in fields to a specific time.
i'm using vb.net 2005 .net 2
Posted

this way...
VB
Dim today As System.DateTime

today = System.DateTime.Now

Dim answer1 = today.AddDays(1)  'date1 += 1
Dim answer2 = today.AddHours(4) 'date2 plus 4 hours
Dim answer3 = today.AddDays(2).AddHours(12) 'date3 plus 2 days and 12 hours
Dim answer4 = today.AddDays(-1).AddHours(-4) 'date4 minus 1 day and 2 hours

Happy Coding!
:)
 
Share this answer
 
Comments
Reza Allahyarzadeh 2-Jan-13 1:34am    
thank you very much you helped me a lot :)
Aarti Meswania 2-Jan-13 1:35am    
welcome dear! :)
Glad to help you! :)
Do you have any sort of books ? Does google work where you live ? How did you learn VB ? Do you know what intellisense is ?

Create a date time. Let's call it date. Now type date followed by a . and the IDE will show you all the methods you have available for that class. There's an AddDays, AddHours, etc. You can give it negative numbers.
 
Share this answer
 
Comments
Reza Allahyarzadeh 2-Jan-13 1:30am    
could you exactly tell me what is the purpose of this damn site? to ask and to be answered.if you don't like it you are not supposed to answer it.THAT'S IT.
ok now don't play smart here, I'm busy with my program now, i checked many sources but couldn't find what I want,i'm in a little bit of hurry and wanted a quick answer which is the name of this place. so I asked here.
I'm so sorry you GOD OF PROGRAMMING I bothered thee!!!!
Christian Graus 2-Jan-13 1:49am    
This site is here to help people. The best help I can give you, is to tell you that if you can't work out these basics, and you're 'in a hurry', that is a bit of an outrage. Who in their right mind would be waiting on work from someone who has no clue what they are doing ? You should learn to program, before being paid to do so.

And I did in fact give you the correct answer.
Reza Allahyarzadeh 20-Feb-13 23:46pm    
I'm not a computer engineer or a programmer,I'm an electronic engineer and i'm writing a GUI to connect to serial ports, i don't intend to waste my precious time in completely learning sth that i won't use in future. i'm damn busy with my vhdl programming and board designing.
and there is no people paying me or waiting for my program , and i'm the boss around here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900