Need help with time function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with time function

WannaBWannaB Posts: 23Member
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?
«1

Comments

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : 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!
  • WannaBWannaB Posts: 23Member
    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.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : 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?
  • WannaBWannaB Posts: 23Member
    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).
  • ColdShineColdShine Posts: 597Member
    : ... time in EST (GMT-5), ...
    ??? What's EST?
    _____________________________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    http://www20.brinkster.com/coldshine[/size]

  • WannaBWannaB Posts: 23Member
    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?
    :

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : : ... time in EST (GMT-5), ...
    : ??? 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.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : 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!
  • ColdShineColdShine Posts: 597Member
    : Eastern Standard Time. Eastern seaboard of the US.

    Yes. You never stop learning...
    _____________________________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    http://www20.brinkster.com/coldshine[/size]

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : : Eastern Standard Time. Eastern seaboard of the US.
    :
    : 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.
«1
Sign In or Register to comment.