+ Reply to Thread
Results 1 to 10 of 10

How to convert from indian time zone to US time zone

Hybrid View

  1. #1
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    How to convert from indian time zone to US time zone

    Hi all,

    I need some serious help here, not sure if this is possible. I have below Time stamp code.

    which inputs current system time, All the system time will be in Time zone of (UTC-05:00) Eastern Time (US & Canada)

    i am fine with system inputting this time.


    The challenge is, some of the system will be in Time zone of (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi.
    Here i need help of Vba code to convert actual Timzone time to (UTC-05:00) Eastern Time (US & Canada) and according to my code
    the converted time will be stamped in active cell.


    Time zone (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi should be converted to (UTC-05:00) Eastern Time (US & Canada).

    my code is as follows,
    Sub Timestamp()
    
    ActiveCell.Value = VBA.Time
    
    
    End Sub
    Thank you

    If I have helped you in someway, use the * icon below to give reputation feedback, it is appreciated.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to convert from indian time zone to US time zone

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: How to convert from indian time zone to US time zone

    Hi ,

    I have attached sample file.

    My system time zone is in (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
    when i ran my code, it published the current time as 04:59:40 Pm.


    I need macro to publish the time in following time zone (UTC-05:00) Eastern Time (US & Canada) always.


    If my system time zone is already in Us & Canada time zone, then macro can publish the current time as it is.
    If my System time zone is in "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi" then macro should convert the system time
    to "(UTC-05:00) Eastern Time (US & Canada)" and publish the revised time.


    So core point is macro should publish only in "(UTC-05:00) Eastern Time (US & Canada)" time zone, current time.

    hope i have given details.
    Attached Files Attached Files

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to convert from indian time zone to US time zone

    If there is 11.5 hours difference between Indian and USA time then an Indian time 4:59:40 PM should convert to a US time of 5:29:40 AM.
    So why do you say it should be 7:30:04 AM?

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,469

    Re: How to convert from indian time zone to US time zone

    .
    Could it be because India does not use Daylight Savings Time and the US does ?

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to convert from indian time zone to US time zone

    Quote Originally Posted by Logit View Post
    .
    Could it be because India does not use Daylight Savings Time and the US does ?
    Yes it's a possibility and the time difference is 9.5 hours not 10.5. But in practice unless there's something in the data to tell the formula to adjust for daylight saving, unless of course that can be deduced from the date, then I don't see how it can be worked out.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,994

    Re: How to convert from indian time zone to US time zone

    Sub Timestamp()
        Dim TimeDif         As Double, _
            DaylightStart   As Date, _
            DaylightEnd     As Date, _
            ThisYear        As Long, _
            IsDaylight      As Boolean
            
        Const March     As Long = 3
        Const November  As Long = 11
        
    '   Generically you can get the nth xday of the month with this formula
    '   =DATE(B2,A2,1+7*n)-WEEKDAY(DATE(B2,A2,8-xday))
    '   daylight start = second (n=2) Sunday (xday =1) in March @ 02:00:00
        
        Const Sunday    As Long = 1
        Const nth       As Long = 2
        Const xday      As Long = 1 'sunday = 1st day of week
        Const TwoAM     As Double = 2 / 24
        
        ThisYear = Year(Now())
        
    'begins at 2:00 a.m. on the second Sunday of March and
        
        DaylightStart = DateValue(March & "/" & 1 + 7 * nth & "/" & ThisYear) - Weekday(DateValue(March & " / " & 8 - xday & " / " & ThisYear))
        DaylightStart = DateValue(DaylightStart) + TwoAM
        
    'ends at 2:00 a.m. on the first Sunday of November
        DaylightEnd = DateValue(November & "/" & 1 + 7 * 1 & "/" & ThisYear)
        DaylightEnd = DaylightEnd + TwoAM
        
    'is daylight in effect?
        IsDaylight = Now >= DaylightStart And Now <= DaylightEnd
        TimeDif = IIf(IsDaylight, 9.5, 10.5) / 24
        
        TimeStampValue = TimeValue(Now() - TimeDif)
    End Sub
    Ben Van Johnson

  8. #8
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: How to convert from indian time zone to US time zone

    Hi Ben and all,

    I appreciate each one of your contribution on this.

    i have tested the code, it does converts Indian time to US time.

    However, if my system time zone is already in US time zone then i dont want any changes in publishing time.
    So if my time zone is in Indian standard time then this conversion should happen.

    is this possible ?

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to convert from indian time zone to US time zone

    The following code is from Chip Pearson. Put it in a standard module and run the AAA procedure. You can then use the StandardName variable value in an IF test to determine whether you need to apply the conversion or not.

     Option Explicit
        
        Private Type SYSTEMTIME
            wYear As Integer
            wMonth As Integer
            wDayOfWeek As Integer
            wDay As Integer
            wHour As Integer
            wMinute As Integer
            wSecond As Integer
            wMilliseconds As Integer
        End Type
        
        
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' NOTE: If you are using the Windows WinAPI Viewer Add-In to get
        ' function declarations, not that there is an error in the
        ' TIME_ZONE_INFORMATION structure. It defines StandardName and
        ' DaylightName As 32. This is fine if you have an Option Base
        ' directive to set the lower bound of arrays to 1. However, if
        ' your Option Base directive is set to 0 or you have no
        ' Option Base diretive, the code won't work. Instead,
        ' change the (32) to (0 To 31).
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        
        Private Type TIME_ZONE_INFORMATION
            Bias As Long
            StandardName(0 To 31) As Integer
            StandardDate As SYSTEMTIME
            StandardBias As Long
            DaylightName(0 To 31) As Integer
            DaylightDate As SYSTEMTIME
            DaylightBias As Long
        End Type
        
        
        ''''''''''''''''''''''''''''''''''''''''''''''
        ' These give symbolic names to the time zone
        ' values returned by GetTimeZoneInformation .
        ''''''''''''''''''''''''''''''''''''''''''''''
        
        Private Enum TIME_ZONE
    
            TIME_ZONE_ID_INVALID = 0        ' Cannot determine DST
            TIME_ZONE_STANDARD = 1          ' Standard Time, not Daylight
            TIME_ZONE_DAYLIGHT = 2          ' Daylight Time, not Standard
    
        End Enum
        
        Private Declare Function GetTimeZoneInformation Lib "kernel32" _
            (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
        
        Private Declare Sub GetSystemTime Lib "kernel32" _
            (lpSystemTime As SYSTEMTIME)
     
        Function IntArrayToString(V As Variant) As String
    
            Dim N As Long
            Dim S As String
            For N = LBound(V) To UBound(V)
                S = S & Chr(V(N))
            Next N
            IntArrayToString = S
    
        End Function
    
        Sub AAA()
    
            Dim TZI As TIME_ZONE_INFORMATION
            Dim DST As TIME_ZONE
            Dim StandardName As String
            
            DST = GetTimeZoneInformation(TZI)
            StandardName = IntArrayToString(TZI.StandardName)
            Debug.Print StandardName
    
        End Sub

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,792

    Re: How to convert from indian time zone to US time zone

    The late, great Chip Pearson - sadly missed on all forums he frequented.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] What formula can convert the date and time zone in Excel??
    By coffeefirst in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-09-2016, 05:19 PM
  2. Input: Time Zone. Output: Current Time
    By imsteve123 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-09-2015, 09:16 PM
  3. Need Help with an user form that convert GTM Time to Other selected Time Zone
    By odoualex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2014, 11:52 AM
  4. Date and time conversion to another time zone
    By RUBEN PARRAS in forum Excel General
    Replies: 1
    Last Post: 05-21-2012, 09:03 PM
  5. How to set a formula to convert the time zone
    By Calculate Date range in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-20-2006, 03:50 AM
  6. How to convert phone area-code to state name and time zone
    By NoYouShmoopie in forum Excel General
    Replies: 2
    Last Post: 10-07-2005, 10:05 AM
  7. Converting Time Values from One Time Zone to Another
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-23-2005, 12:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1