Change system time using vb.netDoes anyone know how to change the system clock using code. I want to be able to set the date and time in my code.<br>Any thoughts??<br>Thanks!!! <br>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Zecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852ahttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852ahttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852aSimone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netDoes anyone know how to change the system clock using code. I want to be able to set the date and time in my code.<br>Any thoughts??<br>Thanks!!! <br>Tue, 31 Oct 2006 15:43:04 Z2006-11-02T15:22:44Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#bbb29834-0bbb-4b49-9004-a959ef5b2a32http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#bbb29834-0bbb-4b49-9004-a959ef5b2a32ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<P>indeed there is, try this:</P> <P>//create a structure:</P> <P><table border="0" cellspacing="0" width="100%"><tr><td width="15"></td><td bgcolor="lightgrey" width="15"></td><td bgcolor="lightgrey"><br><font face="Lucida Console" size="2"></P><FONT color=#0000ff size=2> <font color= "blue">Structure</font></FONT><FONT size=2> SYSTEMTIME<br></FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wYear </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wMonth </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wDayOfWeek </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wDay </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wHour </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wMinute </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wSecond </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wMilliseconds </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font><br><font color= "blue">End</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Structure</font></FONT><br><FONT color=#0000ff size=2></font><br>&nbsp;</td></tr></table></FONT></P> <P><FONT color=#0000ff size=2></FONT>&nbsp;</P> <P><FONT color=#0000ff size=2>import the user32.dll (import the System.Runtime.InteropServices namespace):</FONT></P> <P><FONT color=#0000ff size=2><table border="0" cellspacing="0" width="100%"><tr><td width="15"></td><td bgcolor="lightgrey" width="15"></td><td bgcolor="lightgrey"><br><font face="Lucida Console" size="2"></FONT></P><FONT color=#0000ff size=2><FONT size=2> &lt;DllImport(</FONT><FONT color=#800000 size=2>"kernel32.dll"</FONT><FONT size=2>, setLastError:=</FONT><FONT color=#0000ff size=2><font color= "blue">True</font></FONT><FONT size=2>)&gt;</FONT><FONT color=#0000ff size=2><font color= "blue">public</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">shared</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">function</font></FONT><FONT size=2> SetSystemTime(</FONT><FONT color=#0000ff size=2><font color= "blue">byref</font></FONT><FONT size=2> theDateTime <font color= "blue">as</font> SYSTEMTIME) </FONT><FONT color=#0000ff size=2><font color= "blue">as</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Boolean</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">End</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Function</font></P></FONT></FONT> <FONT color=#0000ff size=2></font><br>&nbsp;</td></tr></table></FONT></P> <P><FONT color=#0000ff size=2>finally, do the job:</FONT></P> <P><FONT color=#0000ff size=2></FONT>&nbsp;</P> <P><FONT color=#0000ff size=2><table border="0" cellspacing="0" width="100%"><tr><td width="15"></td><td bgcolor="lightgrey" width="15"></td><td bgcolor="lightgrey"><br><font face="Lucida Console" size="2"></FONT><br><FONT color=#0000ff size=2><font color= "blue">Dim</font> newDateTime <font color= "blue">as</font> SystemTime()</FONT><br><FONT color=#0000ff size=2>newDateTime.wDay = <STRONG>valueHere</STRONG></FONT><br><FONT color=#0000ff size=2><font color= "blue">if</font> SetSystemTime(newDateTme) <font color= "blue">then</font></FONT><br><FONT color=#0000ff size=2>&nbsp;&nbsp; 'cool, we set it successfully</FONT><br><FONT color=#0000ff size=2>end if</FONT><br><FONT color=#0000ff size=2></font><br>&nbsp;</td></tr></table></FONT></P> <P><FONT color=#0000ff size=2>does this help/work?</FONT></P> <P><FONT color=#0000ff size=2></FONT>&nbsp;</P> <P><FONT color=#0000ff size=2>once you create the Strucure instance, simply set the value you want to the date/time you like</P></FONT>Tue, 31 Oct 2006 16:00:33 Z2006-10-31T16:00:33Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#efc6ea0a-ef1a-4feb-b888-a7a04da7ffe0http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#efc6ea0a-ef1a-4feb-b888-a7a04da7ffe0Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netI am not sure how to import the user32.dll<br>I am not even sure what this is. I'm i declaring something??<br><br><span><span id="_ctl0_MainContent__ctl0_PostForm_ReplyBody" class=txt4><font color="#0000ff" size=2><font color="#0000ff" size=2><font size=2> &lt;DllImport(</font><font color="#800000" size=2>&quot;user32.dll&quot;</font><font size=2>, setLastError:=</font><font color="#0000ff" size=2><font color=blue>True</font></font><font size=2>)&gt;</font><font color="#0000ff" size=2><font color=blue>public</font></font><font size=2> </font><font color="#0000ff" size=2><font color=blue>shared</font></font><font size=2> </font><font color="#0000ff" size=2><font color=blue>function</font></font><font size=2> SetSystemTime(</font><font color="#0000ff" size=2><font color=blue>byref</font></font><font size=2> theDateTime <font color=blue>as</font> SYSTEMTIME) </font><font color="#0000ff" size=2><font color=blue>as</font></font><font size=2> </font><font color="#0000ff" size=2><font color=blue>Boolean</font></font><font size=2> </font><font color="#0000ff" size=2><font color=blue>End</font></font><font size=2> </font><font color="#0000ff" size=2><font color=blue>Function<br></font></font></font></font></span></span>i dont understand this line and where to put it.<br>Tue, 31 Oct 2006 16:26:22 Z2006-10-31T16:26:22Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#c9905be2-8024-441a-8dba-45a265ec67b7http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#c9905be2-8024-441a-8dba-45a265ec67b7ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<P>indeed you are declaring it and thats how you import a dll/Win32 (also known as P/Invoke)</P> <P>this goes at the top of the class, just after public class <STRONG>form1</STRONG> for example, the same applies for the structure decleration. Snippet:</P> <P><table border="0" cellspacing="0" width="100%"><tr><td width="15"></td><td bgcolor="lightgrey" width="15"></td><td bgcolor="lightgrey"><br><font face="Lucida Console" size="2"></P><FONT color=#0000ff size=2> <font color= "blue">Public</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Class</font></FONT><FONT size=2> Form1<br></FONT><FONT color=#0000ff size=2><font color= "blue">Structure</font></FONT><FONT size=2> SYSTEMTIME<br></FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wYear </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wMonth </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wDayOfWeek </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wDay </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wHour </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wMinute </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wSecond </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> wMilliseconds </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Short</font><br>&nbsp;</P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">End</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Structure</font></FONT></P><FONT color=#0000ff size=2><FONT size=2> &lt;DllImport(</FONT><FONT color=#800000 size=2>"kernel32.dll"</FONT><FONT size=2>, setLastError:=</FONT><FONT color=#0000ff size=2><font color= "blue">True</font></FONT><FONT size=2>)&gt; </FONT><FONT color=#0000ff size=2><font color= "blue">Public</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Shared</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Function</font></FONT><FONT size=2> SetSystemTime(</FONT><FONT color=#0000ff size=2><font color= "blue">ByRef</font></FONT><FONT size=2> theDateTime </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> SYSTEMTIME) </FONT><FONT color=#0000ff size=2><font color= "blue">As</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Boolean</font></P></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">End</font></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><font color= "blue">Function</font></FONT><br><FONT color=#0000ff size=2></FONT>&nbsp;<br><FONT color=#0000ff size=2><font color= "blue">private</font> <font color= "blue">sub</font> button1_Click(<font color= "blue">byval</font> sender <font color= "blue">as</font> <font color= "blue">object</font>, <font color= "blue">byval</font> e <font color= "blue">as</font> EventArgs) <font color= "blue">handles</font> button1.Click</FONT><br><FONT color=#0000ff size=2></FONT>&nbsp;<br><FONT color=#0000ff size=2><font color= "blue">end</font> <font color= "blue">sub</font></FONT><br><FONT color=#0000ff size=2></FONT>&nbsp;<br><FONT color=#0000ff size=2>'and so on</P></FONT></FONT> </font><br>&nbsp;</td></tr></table></P> <P>&nbsp;</P> <P>edit: change user32 to kernel32</P>Tue, 31 Oct 2006 16:33:02 Z2006-10-31T16:33:02Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#b6bd7f1f-c307-4cb5-8b04-51a0282f45c2http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#b6bd7f1f-c307-4cb5-8b04-51a0282f45c2Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netThis is not doing what i want. <br>what I want to do is connect the system time to my program<br>i have a interface where the user can go in and click (for example: the + and - button to increase or decrease the number to change the hour and minutes.) I want them to be able to change the time and date as if they were doing it using the windows date and time properties. When they change the time in the program i want the system clock to also change accordingly. I know how write code to set the current date and time by clicking a button. I just need to know how to get the clock in the program with the ability to adjust the date and time. <br>Any thoughts??<br>Thanks!!<br><br>Tue, 31 Oct 2006 20:22:11 Z2006-10-31T20:22:11Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d9a76e06-23a2-4fa2-a8a1-71c4a8c63255http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d9a76e06-23a2-4fa2-a8a1-71c4a8c63255ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<P>which program? As you may know, the code above does this, it sets the system date/time according to what ever you have set in the structure SYSTEMTIME. in regards to your program, what program is this? Something you have made or some other 3rd party software?</P> <P>I guess when you implemented say a numericupdown control, this could be, as an example, the day to set. Then you set this value to the structure wDay, and you do the same for the rest of the properties. Once done and they hit the button save, do the code above</P>Tue, 31 Oct 2006 20:29:51 Z2006-10-31T20:29:51Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d4bdec74-6d85-40e7-9f39-5623de3d9c91http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d4bdec74-6d85-40e7-9f39-5623de3d9c91Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netIt is not a third party program. I dont want to just click a button and the date and time is displayed. The program i am using is time orentied. The time in the program keeps up with the system time or whatever time u set it to. I want to be able to edit the time through a form in my program. NOT just click a button and set the current date and time. I want what i stated in my previous post.<br>Tue, 31 Oct 2006 20:47:24 Z2006-10-31T20:47:24Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#14023ac4-1b48-404d-97c2-672fa600d4e1http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#14023ac4-1b48-404d-97c2-672fa600d4e1ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<p>to get the system time:</p> <p>DateTime.Now</p> <p>returns back the current time. So you could say, place this on a timer on your form, and set the timer interval to say, 1 second (1000 ms's) then do, on the timer tick event:</p> <p>Me.theLabel.Text = DateTime.Now.ToString()</p> <p> </p> <p>this will keep the label updated every second of the current time the system has.</p> <p>if you create your own DateTime object, again using the approach above, you can then add 1 second to the DateTime object you created in your program. Example:</p> <p> </p> <p>Dim theCustomDateTime as DateTime = new DateTime(<strong>year, month, day, hour, minute, second</strong>) 'declare this globally</p> <p> </p> <p>'timer tick event:</p> <p>Me.theCustomDateTime = Me.theCustomDateTime.AddSeconds(1)</p> <p>Me.theLabel.Text = Me.theCustomDateTime.ToString()</p> <p> </p> <p>something more towards your area?</p>Tue, 31 Oct 2006 21:01:40 Z2006-10-31T21:08:31Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#571817a7-3a4e-47a2-960c-a12dcbc5c85ehttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#571817a7-3a4e-47a2-960c-a12dcbc5c85eSimone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netI dont think you are exactly reading my post. <br>I dont just want the time on the form<br>I have several buttons. ex. first button has a plus sign, second button has a minus sign. when i click on the button with the plus sign it should increase the hour or minute by 1. It is just as if i was setting the time on the pc clock. I hope this is clear.<br>Thanks!!<br>Wed, 01 Nov 2006 17:05:12 Z2006-11-01T17:05:12Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#bc59f931-15ec-4212-a354-49bb6a8cb088http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#bc59f931-15ec-4212-a354-49bb6a8cb088ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<P>well yes the above does it pretty much except you need to place the code in the right place. So declare a datetime object globally as shown. Then in your plus button, add 1 hour (for example) to the datetime object stored globally:</P> <P>Me.theDateTime = Me.theDateTime.AddHours(1)</P> <P>for minus button, do the same thing but do -1 instead to take away 1 hour. Same goes for minutes, seconds, milliseconds, days, months and years.</P>Wed, 01 Nov 2006 19:01:14 Z2006-11-01T20:00:32Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#794c9d34-a507-4031-a7c1-c4d2354f8709http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#794c9d34-a507-4031-a7c1-c4d2354f8709Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netwhen i do the global declare of Public theCustomDateTime As DateTime = New DateTime(Year, Month, Day, Hour, Minute, Second) like you suggested it gives me this message.<br><br>Argument not specified for parameter 'DateValue' of 'Public Function <span style="color:rgb(255, 0, 0)">year</span> (DateValue as Date) as integer'<br><br><br>Wed, 01 Nov 2006 19:56:34 Z2006-11-01T19:56:34Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d29aac91-aa69-42c3-95f6-9a92afb60469http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d29aac91-aa69-42c3-95f6-9a92afb60469ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<p>:-) you need to replace the bold words as those are parameter values. In the IDE when you type code and you open the bracket &quot;(&quot;, it will give you a tooltip explaining what overloads this class has, those overloads I put in here for you as an example. So if you just wanted to start from todays date/time then:</p> <p>Dim theCustomDateTime as DateTime = DateTime.Now</p> <p> </p> <p>and thats it! It will create a datetime object with the current time (system time) in a global variable. If you wanted to specify the year/month/day/hour/minute/second etc... then you fill in the appropriate parameter values:</p> <p>Dim <font size=2>theCustomDateTime As DateTime = New DateTime(2006, 11, 1, 02, 11, 30)</font></p> <p><font size=2></font> </p>Wed, 01 Nov 2006 20:00:10 Z2006-11-01T20:00:10Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#fdfc3910-6f61-4ae4-a2ab-dead8a1f01e8http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#fdfc3910-6f61-4ae4-a2ab-dead8a1f01e8Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.nethere is what i have <br>Global declared <br><br>Public theCustomDateTime As DateTime = New DateTime(Today.Hour)<br><br>i have a button and a textbox<br><br>in the button code i have<br>txthour.Text = theCustomDateTime.AddHours(1)<br><br>when i click the button 1 displays in the textbox but when i click it again nothing happens. I want each time i click the button the hour increases by 1 and goes until 23. This should be changing the system clock so that whatever hour i put it as the system clock will change to that hour.<br>Wed, 01 Nov 2006 20:11:50 Z2006-11-01T20:11:50Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#4f6ba70e-b749-446a-8c48-0801e32ffef6http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#4f6ba70e-b749-446a-8c48-0801e32ffef6ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<p>its because you should be doing it this way, reassigning it back to the global variable as shown earlier:</p> <p>Me.theCustomDateTime = Me.theCustomDateTime.AddHours(1)</p> <p>Me.txthour.Text = Me.theCustomDateTime.ToString()</p>Wed, 01 Nov 2006 20:16:09 Z2006-11-01T20:28:15Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#7f0dc5c6-5f13-4d4a-b1d0-e4c616307fb9http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#7f0dc5c6-5f13-4d4a-b1d0-e4c616307fb9Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netok, that works, but why does it also show the date in the box. <br>All i want to appear in the box is just the hour of day.<br>Wed, 01 Nov 2006 20:25:49 Z2006-11-01T20:25:49Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#70f9381c-6b40-4584-acfa-385cfc2df3d1http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#70f9381c-6b40-4584-acfa-385cfc2df3d1ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<p>the reason it shows the date is because thats what the ToString() does, it shows the date/time string of the datetime object. If you just want the hour, get the hour property:</p> <p>Me.theTextBox.Text = Me.theCustomDateTime.ToString(&quot;HH&quot;)</p> <p>or</p> <p>Me.theTextBox.Text = Me.theCustomDateTime.Hour.ToString()</p> <p> </p> <p><a title="http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx" href="http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx">http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx</a></p>Wed, 01 Nov 2006 20:30:12 Z2006-11-01T20:30:21Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#4567eae2-058a-424f-96d7-36d7cf1ae79ahttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#4567eae2-058a-424f-96d7-36d7cf1ae79aSimone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netThanks for your help so far. I got the minute date and month to work but i cannot get the year to work. It seem to only count it if i start from 1, but i cannot start from 1 because we are in the year 2006. i want to start from 2006 and have it count by 1 but it does not work that way, it jumps from 2006 to 2007 to 4013, its like it is doubling the number.<br>can you help??<br>Thanks!!<br>Wed, 01 Nov 2006 20:52:45 Z2006-11-01T20:52:45Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#0aa633bc-f164-4665-9e8c-763d3b16588ehttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#0aa633bc-f164-4665-9e8c-763d3b16588eahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.netsomething must be wrong. can you show us the code for that? In fact, post the entire solution...I hope you are not adding values in the timer event....Wed, 01 Nov 2006 20:58:19 Z2006-11-01T20:58:19Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#f19a35de-5a51-413b-80e8-249d126e5519http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#f19a35de-5a51-413b-80e8-249d126e5519Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netThis is what i declared globally<br> Public theCustomDateTime As DateTime = New DateTime(1)<br><br>here is my code for the year<br>Private Sub btnyear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnyear.Click<br>theCustomDateTime = theCustomDateTime.AddYears(2006)<br>        txtyear.Text = theCustomDateTime.ToString(&quot;yyyy&quot;)<br><br>this works fine for the month hour minute and date, i guess because i am starting from 1<br><br>ALSO:<br>when i do the (-1)<br>it does not go all the way in reverse. I want it to go backwards all the way.<br>for example:<br>for the month which will go from 1-31<br>when i do the minus i want it to go 31,30,29 etc.<br>I hope that was clear. <br>Wed, 01 Nov 2006 21:06:53 Z2006-11-01T21:06:53Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#63c97c84-216c-4895-bd12-f8283b5428d2http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#63c97c84-216c-4895-bd12-f8283b5428d2ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<P>your not doing it correctly :-)</P> <P>you are adding 2006 to the existing years value in the btnYear click, so on every click&nbsp;it will jump up...as you are experiencing (1 + 2006 = 2007, then 2007 + 2006 = 4013...and so on, then next click: 4013 + 2006 = 6019...and so on)</P> <P>Now in regards to making it go back, what you had done, and suggested, is correct but I thought you wanted this to happen (or even adding) in the minus button whenever its pressed? So if minus button is pressed, then you take 1 away from the year or 1 away from the hour or 1 away from the minute or whatever it is you want to take the value 1 away from.</P> <P>original post:</P> <P><BLOCKQUOTE><table width="85%"><tr><td class="quoteTable"><table width="100%"><tr><td width="100%" valign="top" class="txt4"></P> <P>I have several buttons. ex. <FONT color=#ff0000>first button has a plus sign</FONT>, <FONT color=#0000ff>second button has a minus sign</FONT>. when i click on the button with the plus sign it should increase the hour or minute by 1.</P> <P></td></tr></table></td></tr></table></BLOCKQUOTE></P> <P>&nbsp;</P> <P>so as you have done, declare globally a DateTime object:</P> <P>private theCustomDateTime as new DateTime(1, 1, 1) 'year 1, month 1, day 1</P> <P>&nbsp;</P> <P>'timer tick event:</P> <P>private sub Timer1_Tick(byval sender as object, byval e as EventArgs) handles Timer.Tick</P> <P>&nbsp;&nbsp; Me.theTextBox.Text = Me.theCustomDateTime.ToString("yyyy") 'or whatever format you want to show to the textbox</P> <P>end sub</P> <P>&nbsp;</P> <P><FONT color=#ff0000>plus button</FONT>:</P> <P>private sub cmdPlus_Click(byval object as sender, byval e as EventArgs) handles cmdPlus.Click</P> <P>&nbsp;&nbsp; Me.theCustomDateTime = Me.theCustomDateTime.AddYears(1) 'add 1 year from the current year. pressing it, will increase the year</P> <P>end sub</P> <P>&nbsp;</P> <P><FONT color=#0000ff>'minus button:</FONT></P> <P><FONT color=#0000ff>private sub cmdMinus_Click(byval object as sender, byval e as EventArgs) handles cmdMinus.Click</FONT></P> <P><FONT color=#0000ff>&nbsp;&nbsp; Me.theCustomDateTime = Me.theCustomDateTime.AddYears(-1) 'takes 1 away from the current year value, pressing it again will DECREASE the year</FONT></P> <P><FONT color=#0000ff>end sub</FONT></P> <P><FONT color=#0000ff></FONT>&nbsp;</P> <P><FONT color=#0000ff>is this not what you are after? Sorry if this is not helping, im still confused</FONT></P>Wed, 01 Nov 2006 21:44:44 Z2006-11-01T21:44:44Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#f90786ca-3317-4f8b-8976-f72258a418bbhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#f90786ca-3317-4f8b-8976-f72258a418bbSimone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netI am not sure what you are saying about the timer tick event.<br>However, i added a timer and in the event i put<br>txtyears.text= thecustomdatetime.tostring(&quot;yyyy&quot;)<br>and nothing happens.<br>Lets forget about going back with the minus for the moment. <br>What i really need to get working is the &quot;year&quot; <br>How can i get the year to start from 2005 or 2006 or start it from wherever i want it to so that when i click the button it increase the year by 1. It works for the others like, month, minutes, hour etc. <br>Wed, 01 Nov 2006 22:01:14 Z2006-11-01T22:01:14Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#2ef1662f-a8b9-4e96-9dea-c09ece2fe4eehttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#2ef1662f-a8b9-4e96-9dea-c09ece2fe4eeahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<P>this would be done when initializing/constructing the global dateTime variable.</P> <P>Dim theCustomDateTime as DateTime = DateTime.Now 'gets the current datetime and assigns it to the variable (current year, current month, current day, current hour, current minute, current second, current millisecond)</P> <P>OR</P> <P>Dim theCustomDateTime as new&nbsp;DateTime(<STRONG>yourYearValueHere, yourMonthValueHere, yourDayValueHere</STRONG>)</P> <P><a target="_blank" title="http://msdn2.microsoft.com/en-us/library/system.datetime.datetime.aspx" href="http://msdn2.microsoft.com/en-us/library/system.datetime.datetime.aspx">http://msdn2.microsoft.com/en-us/library/system.datetime.datetime.aspx</a></P> <P>&nbsp;</P> <P>does this help for this part?</P> <P>now for adding 1 to the year, the current way you have, its fine - you don't need to change any method for that, the buttons will work fine as shown in my example. All you need to worry about is creating the object globally, as shown above and set it to the values you want. Look at the constructor (see link) to see what values/parameters it takes to construct the object and initialize it with your values that you give it in the constructor.</P>Wed, 01 Nov 2006 22:07:57 Z2006-11-02T15:22:37Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#734caadf-45f0-4d49-a4f2-da3b7ca0ad60http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#734caadf-45f0-4d49-a4f2-da3b7ca0ad60Mekkihttp://social.msdn.microsoft.com/Profile/en-US/?user=MekkiChange system time using vb.net<p class=MsoNormal style="margin:0in 0in 0pt"><font face="Times New Roman" size=4>It seems that Microsoft did not provide us with a way by which we can <font size=5><i>control</i> </font>the system time programmatically.</font></p> <p class=MsoNormal style="margin:0in 0in 0pt"><font face="Times New Roman" size=4>All the methods provided by Microsoft are “read only methods”. We can add subtract to the <font size=5>current system date</font><em>.</em> We have no way to change the system date/time and their format. </font></p> <p class=MsoNormal style="margin:0in 0in 0pt"><font face="Times New Roman" size=5>It is very bad that to this by going to System32 !</font></p> <p class=MsoNormal style="margin:0in 0in 0pt"><font face="Times New Roman" size=5>We need a .Net interface to perform such tasks!</font></p> <p class=MsoNormal style="margin:0in 0in 0pt"> </p>Thu, 02 Nov 2006 07:47:05 Z2006-11-02T07:47:05Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#1c4c7bc8-4448-4446-99b2-5d44bb83fb58http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#1c4c7bc8-4448-4446-99b2-5d44bb83fb58Simone1http://social.msdn.microsoft.com/Profile/en-US/?user=Simone1Change system time using vb.netThe year still does not work.<br>Here is how i declared globally:<br><br>Public CustomDateTime As New DateTime(2006)<br>Now, here is my code:<br><br>Private Sub btnyear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnyear.Click<br>      <br>        CustomDateTime = CustomDateTime.AddYears(2006)<br>        txtyear.Text = CustomDateTime.ToString(&quot;yyyy&quot;)<br>    End Sub<br>I tried it with both 1 and 2006. The 2006 does not work, when i click the button to make it go up one more year it does not move. However when i use 1 it works but i dont want to start from one because from 1 - 2006 is alot of clicks. <br>Thu, 02 Nov 2006 15:10:03 Z2006-11-02T15:10:03Zhttp://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d0c35f01-d020-49e1-ac9b-27e7e934d697http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/ecb3b06e-8e3f-4c0f-9fc3-5e3fd28a852a#d0c35f01-d020-49e1-ac9b-27e7e934d697ahmedilyashttp://social.msdn.microsoft.com/Profile/en-US/?user=ahmedilyasChange system time using vb.net<p>again, you need to read the link supplied. the 2006 you are giving is ticks, not the actual year value. ticks is the time rather/elapsed. you need to construct a PROPER year datetime which is done this way:</p> <p>private CustomDateTime as new DateTime(2006, <strong>yourMonthValue, yourDayValue</strong>)</p> <p>replace the bold text with whatever month and day value you want. This is how you create a proper datetime object which represents the proper date (day/month/year)</p> <p>if you do it the way you are right now, you are creating an instance of DateTime which holds the number of ticks. (Date and time elapsed in 100 nano second units)</p>Thu, 02 Nov 2006 15:22:23 Z2006-11-02T15:22:44Z