How to Check a datetime is in GMT or BST

mike08

Board Regular
Joined
Oct 29, 2008
Messages
167
Hi mates,

Once more i need ur valuable help. In excel, i have a column
"Received On" contains the datetime of a mail received , it is in BST, sometimes it should be in GMT depends on the date or year, i'm not sure.
So what my query is, in another column, i have to check if the datetime in "Received On' is in BST, convert this datetime to GMT, otherwise if this time is in GMT, i don't need to add anything just copy that datetime alone.

eg: ie in ColumnA is the Datetime value

if ColumnA=BST then
ColumnB=ColumnA+1/24 (ie convert BST to GMT)
else if ColumnA=GMT then
ColumnB=ColumnA (ie not need to change, becz already columnA is in GMT)

are u clear? if u have confusion, pls ask me.

Thanks in advance for any help
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Thanks Andrew,

that means using scripting only, i can solve my query. But is there any way to check this using excel static functions
 
Upvote 0
If you want to convert BST to GMT you need to subtract an hour. Given that BST runs from 01:00 on the last Sunday in March to 01:00 on the last Sunday in October you can use this formula to subtract an hour from a "datetime" in A2 when required or leave alone if it's already BST.

=IF(A2="","",A2-IF(PRODUCT(A2-DATE(YEAR(A2),{4,11},1-WEEKDAY(DATE(YEAR(A2),{4,11},0)))-1/24)<0,1)/24)

Note that for times between 01:00 and 02:00 on last Sunday in October it's impossible to tell whether it's BST or GMT because that hour is covered twice, once in BST then once in GMT.....

This formula is valid for current dates but may not be valid if you go back more than 10 years as the changeover dates were sometimes different.
 
Upvote 0
Hi barry,

its great, but i am not familiar with functions you used, i tried a lot my own way, no luck to understand. sorry, so can u explain each functions u used in the formula? pls...
Why u used A2="", not getting , i think are u happy to help me or any one can ........
 
Upvote 0
The part

=IF(A2="",""....just checks whether A2 is empty and returns a blank if it is......if you always have a datetime in A2 you can just use this:

=A2-(PRODUCT(A2-DATE(YEAR(A2),{4,11},1-WEEKDAY(DATE(YEAR(A2),{4,11},0)))-1/24)<0)/24

The general principle is as follows:

The DATE part generates an array of two dates - both the start and end of BST for the year in question. These dates are subtracted from the datetime in A2 (with an adjustment for the time of day of the BST/GMT switch). If the resultant numbers are both positive then A2 is after the end of BST, if both are negative then A2 is before BST.....if you have one of each then it must be within the BST period.

Using PRODUCT multiplies the two numbers, so a negative result from the Product of the 2 indicates 1 of each, i.e. within BST and so one hour (1/24) is subtracted.

The dates themselves are generated using a variation of this formula

=DATE(YEAR(A2),4,1-WEEKDAY(DATE(YEAR(A2),4,0)))

This finds the last Sunday in March (by finding the first Sunday in April and subtracting 7), so we can extend it to find both the last Sunday in March and the last Sunday in October by replacing 4 with {4,11}
 
Upvote 0
Hi thanks a lot man, u r really great, along with the solution, u are giving me a detailed explanation. its very useful for me.
thanks once more
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,910
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top