Beginner VB

Moderators: None (Apply to moderate this forum)
Number of threads: 1233
Number of posts: 2978

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help with time function Posted by WannaB on 23 Jun 2002 at 7:58 AM
I am having a problem adding hous to the current time to display time in another time zone. How would I go about this? For example, my current time is 5:00 pm and I wanted to add 4 hours to it to show the time in another city, how could I add the 4 hours?
Report
Re: Need help with time function Posted by KDivad Leahcim on 24 Jun 2002 at 1:13 PM
: I am having a problem adding hous to the current time to display time in another time zone. How would I go about this? For example, my current time is 5:00 pm and I wanted to add 4 hours to it to show the time in another city, how could I add the 4 hours?
:

Use the DateAdd function:

DateAdd(Interval, Amount, FirstDate)

Interval can be one of the following:

"s" - seconds
"n" - minutes 'Yes, "n" is minutes.
"h" - hours
"d" - days
"m" - months 'See? Only one could be "m" and they gave it to months
"y" - years

Amount is the number of intervals (seconds, minutes, etc.) that you want to add.

OriginalDate is the time you want to add to.

Assuming your date is in Text1 and you show in Text2:

Text2.Text = DateAdd("h", 4, Text1.Text)

Hope this helps!
Report
Re: Need help with time function Posted by WannaB on 26 Jun 2002 at 2:31 PM
Okay, thanks for your help, but I still seem to be running into problems. I have two text boxes, two combo boxes with time zones. When the user clicks a time zone from each cmb, the correct time for that area should appear in the corresponding boxes. I could not, using that function, add the hours such as GMT +1, GMT+2, etc, to adjust the time.
Report
Re: Need help with time function Posted by KDivad Leahcim on 27 Jun 2002 at 7:22 AM
: Okay, thanks for your help, but I still seem to be running into problems. I have two text boxes, two combo boxes with time zones. When the user clicks a time zone from each cmb, the correct time for that area should appear in the corresponding boxes. I could not, using that function, add the hours such as GMT +1, GMT+2, etc, to adjust the time.
:

My time is GMT-6. If I put:

MsgBox DateAdd("h", 6, Now)

I will get the date and time for GMT because I added 6 to my time.

What you need is to subtract their GMT time (mine is -6) and then add the new GMT time (or vice versa).

For example, if I wanted to find my time in EST (GMT-5), I would use this:

MsgBox DateAdd("h", -5 - -6, Now)

And it shows my time plus one hour, which is correct.


To help you more (if you need it), I have three questions:
1. Are the two sets (one textbox and one combobox) related in any way?
2. Do you know about the ItemData property?
3. What are the contents of your comboboxes? Is it just +1, +2, etc? Or is it like Windows' with several time zones duplicated?
Report
Re: Need help with time function Posted by WannaB on 27 Jun 2002 at 9:46 AM
Thanks again, but I haven't had a chance to work with this yet. I just want to answer your questions.

1)The text box should display the time for the zone clicked, with a label displaying the location.

2)I am not sure of what you mean by ItemData property.

3)It is very much like the Windows clock, except I want to be able to click on the 2 combo boxes and be able to display the two separate times(in text boxes), simultaneously with their respective locations (in a labels, of course).
Report
Out of topic Posted by ColdShine on 27 Jun 2002 at 11:25 AM
: ... time in EST (GMT-5), ...
??? What's EST?
_____________________________
ColdShine
http://www20.brinkster.com/coldshine


Report
Re: Out of topic Posted by KDivad Leahcim on 28 Jun 2002 at 1:03 PM
: : ... time in EST (GMT-5), ...
: ??? What's EST?
: _____________________________
: ColdShine
: http://www20.brinkster.com/coldshine

:
:

Eastern Standard Time. Eastern seaboard of the US.
Report
Thanx Posted by ColdShine on 30 Jun 2002 at 5:18 AM
: Eastern Standard Time. Eastern seaboard of the US.

Yes. You never stop learning...
_____________________________
ColdShine
http://www20.brinkster.com/coldshine


Report
Re: Thanx Posted by KDivad Leahcim on 30 Jun 2002 at 8:07 AM
: : Eastern Standard Time. Eastern seaboard of the US.
:
: Yes. You never stop learning...
: _____________________________
: ColdShine
: http://www20.brinkster.com/coldshine

:
:

When you think you know it all, a 5yr old will come along and tell you something new. <grin>

Any day you learn something is a day not wasted.
Report
Re: Need help with time function Posted by WannaB on 28 Jun 2002 at 4:58 AM
I was able to increment/decrement the hours, but I have run into I guess a technical problem. Why when I click on any zone, the correct time is displayed for the moment and it doesn't change. The seconds aren't moving, nothing changes unless I click the zone again?




: : Okay, thanks for your help, but I still seem to be running into problems. I have two text boxes, two combo boxes with time zones. When the user clicks a time zone from each cmb, the correct time for that area should appear in the corresponding boxes. I could not, using that function, add the hours such as GMT +1, GMT+2, etc, to adjust the time.
: :
:
: My time is GMT-6. If I put:
:
: MsgBox DateAdd("h", 6, Now)
:
: I will get the date and time for GMT because I added 6 to my time.
:
: What you need is to subtract their GMT time (mine is -6) and then add the new GMT time (or vice versa).
:
: For example, if I wanted to find my time in EST (GMT-5), I would use this:
:
: MsgBox DateAdd("h", -5 - -6, Now)
:
: And it shows my time plus one hour, which is correct.
:
:
: To help you more (if you need it), I have three questions:
: 1. Are the two sets (one textbox and one combobox) related in any way?
: 2. Do you know about the ItemData property?
: 3. What are the contents of your comboboxes? Is it just +1, +2, etc? Or is it like Windows' with several time zones duplicated?
:

Report
Re: Need help with time function Posted by KDivad Leahcim on 28 Jun 2002 at 1:10 PM
: I was able to increment/decrement the hours, but I have run into I guess a technical problem. Why when I click on any zone, the correct time is displayed for the moment and it doesn't change. The seconds aren't moving, nothing changes unless I click the zone again?
:

Ah! I didn't know you wanted a clock!

Add a timer to your form. Set it's Interval property to 100. Move all calculations and display code from the combobox _Click event to the Timer1_Timer event. This way, every time the timer fires (about every 1/10th of a second), it will do the same thing as when you clicked. Optionally, you can place a single line (Timer1_Timer) in the click event that triggers the timer event for immediate updating. But few people will notice a delay of 1/10th sec or less...

If you need more help, you can send your project to me and I'll adjust it if you would like me to. Just let me know!
Report
Re: Need help with time function Posted by paulj59 on 2 Jul 2002 at 4:37 PM
: : I am having a problem adding hous to the current time to display time in another time zone. How would I go about this? For example, my current time is 5:00 pm and I wanted to add 4 hours to it to show the time in another city, how could I add the 4 hours?
: :
:
: Use the DateAdd function:
:
: DateAdd(Interval, Amount, FirstDate)
:
: Interval can be one of the following:
:
: "s" - seconds
: "n" - minutes 'Yes, "n" is minutes.
: "h" - hours
: "d" - days
: "m" - months 'See? Only one could be "m" and they gave it to months
: "y" - years
:
: Amount is the number of intervals (seconds, minutes, etc.) that you want to add.
:
: OriginalDate is the time you want to add to.
:
: Assuming your date is in Text1 and you show in Text2:
:
: Text2.Text = DateAdd("h", 4, Text1.Text)
:
: Hope this helps!
:

Now()+4 = 4 days from now
Now()+(4#/24#) = 4 hours from now
Now()+(4#/1440#) = 4 minutes from now
Now()+(4#/86400#) = 4 seconds from now

It took me years to discover that a Date variable is a double representing the number of days from a relative 0 (Dec 30,1899 in VB, Jan 1,1900 in SQL Server). 12 hours = 0.5



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.