Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: DateTime VB.NET
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 1-Jan-13 17:54pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

this way...
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!
Smile | :)
  Permalink  
Comments
Reza Allahyarzadeh at 2-Jan-13 1:34am
   
thank you very much you helped me a lot :)
Aarti Meswania at 2-Jan-13 1:35am
   
welcome dear! :)
Glad to help you! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Reza Allahyarzadeh at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100