当前位置: 动力学知识库 > 问答 > 编程问答 >

excel vba - How to convert Ireland time to Indian time?

问题描述:

In Excel I want to change a date and time value received in Ireland format to the format used in India.

I tried this:

14/09/2016 13:51:38-time(5,30,0)

but I get a #value error.

网友答案:

suppose your Irish time (14/09/2016 13:51:38) is in A1 then your Indian time: $A$1+((5+30/60)/24) with of course the time difference being 5 hours 30 minutes in this example

网友答案:

As you were looking for a VBA solution, I would use DateAdd here: DateAdd("n", -330, "14/09/2016 13:51:38") in my example below I defined date ranges as I prefer to work that way, you could easily mould this into a loop.

Private Sub test()

Dim irTime, inTime As Date

irTime = Sheets(5).Cells(1, 1).Value
inTime = DateAdd("n", -330, irTime)

Sheets(5).Cells(1, 3).Value = inTime

End Sub

If you are still getting #Value errors I would look at the formatting of your Irish times and make sure taht they are all consitant and correctly formatted (don't forget to back-up incase you lose data playing around with formats).

This is my go-to bookmark for DateAdd as I always forget the "n" interval for minutes, you might find it useful.

分享给朋友:
您可能感兴趣的文章:
随机阅读: