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?
Comments
:
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!
:
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?
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).
??? What's EST?
_____________________________
[size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
http://www20.brinkster.com/coldshine[/size]
: : 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?
:
: ??? What's EST?
: _____________________________
: [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
: http://www20.brinkster.com/coldshine[/size]
:
:
Eastern Standard Time. Eastern seaboard of the US.
:
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!
Yes. You never stop learning...
_____________________________
[size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
http://www20.brinkster.com/coldshine[/size]
:
: Yes. You never stop learning...
: _____________________________
: [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
: http://www20.brinkster.com/coldshine[/size]
:
:
When you think you know it all, a 5yr old will come along and tell you something new.
Any day you learn something is a day not wasted.
: :
:
: 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