INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Check if date is BST or GMT, timezone help

Check if date is BST or GMT, timezone help

(OP)
I need a function to check whether a given date falls within British Summer Time or Greenwich Mean Time.

For example:

24/10/2015 is the last day of British Summer Time
25/10/2015 is the first day of Greenwich Mean Time

In a perfect world, my function would look something like this:

CODE

MyDate = "24/10/2015"
<check if MyDate falls within UK BST or GMT>
Result = "This date is BST" 







RE: Check if date is BST or GMT, timezone help

And what have you tried so far?

Look at the Date object in Javascript.

http://www.w3schools.com/jsref/jsref_obj_date.asp

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Check if date is BST or GMT, timezone help

Already posted this in the ASP thread so may as well post it here as well


CODE --> HTML

<head>
<script type="text/javascript">

function getDayName(index,long,firstDay) {
// returns name of day
// index = day code 0 to 6 : REQUIRED
// long = true: return long name (Sunday): false = return short (Sun)
// firstDay = first day of the week 0 = Sunday (default); 1 - 5 = Monday; 6 = Saturday
if (firstDay == undefined) {
	firstDay = 0;
	}
if (long == undefined) {
	long = true;
	}

var tmp = ""
var Name = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var shortName = new Array("Sun","Mon","Tues","Wed","Thurs","Fri","Sat");
	if (firstDay > 0 && firstDay < 6) {
		tmp = Name.shift();
		Name.push(tmp);
		tmp = shortName.shift();
		shortName.push(tmp);
	} else if (firstDay == 6) {
		tmp = Name.pop();
		Name.unshift(tmp);
		tmp = shortName.pop();
		shortName.unshift(tmp);
	}

	if (long) {
		return Name[index];
	} else {
		return shortName[index];
	}

}

function addDateSuffix(day) {
if (day > 0 && day < 32) {
	if (day == 1  | day == 21 | day == 31) {
		return day.toString() + "st";
	} else if (day == 2  | day == 22) {
		return day.toString() + "nd";
	} else if (day == 3  | day == 23) {
		return day.toString() + "rd";
	} else {
		return day.toString() + "th";
	}
} else {
	return "";
}
}

function getMonthName(index,long) {
if (long == undefined) {
	long = true;
}
var Name=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var shortName=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	if (long) {
		return Name[index];
	} else {
		return shortName[index];
	}
}

function dateFormat(formatString,dateValue) {
var retVal = formatString;
var date = new Date(dateValue);
var fmt = formatString;

var day = date.getDay();
var d = date.getDate().toString();
var m = (date.getMonth()+1).toString();

if (fmt.indexOf("YYYY") > -1 | fmt.indexOf("yyyy") > -1 ) {
		retVal = retVal.replace(/YYYY/i,date.getFullYear().toString());
	} else if (fmt.indexOf("YY") > -1 | fmt.indexOf("yy") > -1) {
		retVal = retVal.replace(/yy/i,date.getFullYear().toString());
}
if (fmt.indexOf("DD") > -1) {
		retVal = retVal.replace(/DD/,getDayName(date.getDay()) + " " + addDateSuffix(date.getDate()));
	} else if (fmt.indexOf("D") > -1) {
		retVal = retVal.replace(/D\b/,getDayName(date.getDay(),false) + " " + addDateSuffix(date.getDate()));
	} else if (fmt.indexOf("dd") > -1) {
		if (d.length == 1) {
			d = "0" + d;
	}
	retVal = retVal.replace(/dd/,d);
	} else if (fmt.indexOf("d") > -1) {
	retVal = retVal.replace(/d\b/,d);
}

if (fmt.indexOf("MM") > -1) {
		retVal = retVal.replace(/MM/,getMonthName(date.getMonth()) + " ") ;
	} else if (fmt.indexOf("M") > -1) {
		retVal = retVal.replace(/M\b/,getMonthName(date.getMonth(),false) + " " );
	} else if (fmt.indexOf("mm") > -1) {
		if (m.length == 1) {
			m = "0" + m;
	}
	retVal = retVal.replace(/mm/,m);
	} else if (fmt.indexOf("m") > -1) {
	retVal = retVal.replace(/m/,m);
}
return retVal;
}
</script>
</head>

<h2 class="italic">Javascript dateFormat Function</h2>


<script type="text/javascript">
document.write(dateFormat("DD MM YYYY",Date()));
document.write("<br>");
document.write(dateFormat("dd MM yy",Date()));
document.write("<br>");
document.write(dateFormat("d/m/yy",Date()));
document.write("<br>");
document.write(dateFormat("dd mm yy",Date()));
document.write("<br>");
document.write(dateFormat("D M yy",Date()));
document.write("<br>");
document.write(getDayName(2,6,true));
document.write("<br>");
document.write(addDateSuffix(31));
document.write("<br>");

</script> 

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Check if date is BST or GMT, timezone help

(OP)
Thanks Chris. I appreciate your efforts but this does not resolve my problem.

I have been very specific as to what I need.

This code does not allow me to enter a date and then calculate whether or not that date falls within UK British Summer Time or Greenwich Mean Time.

Any other suggestions are welcome.

RE: Check if date is BST or GMT, timezone help

HOW can you EVEN KNOW if any particular time is in a particular time zone UNLESS you already KNOW what time zone the user is in.


Time is arbitrary, let's say at this moment it is 22:25 on Monday the 10th of August can YOU tell me what time zone that is and whether Daylight Saving adjustment is in force or not?
(that is not the actual time here by the way).

The problem is that you are not really understanding what you are asking for and trying to get at the wrong way.

You cannot tell whether any time, given ONLY the time and date, is GMT, BST, EST, PST, CET or BBC, you EITHER have to know the hour offset (+ or -) from GMT is OR the timezone the end user is in.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Check if date is BST or GMT, timezone help

(OP)
My customer is booking a taxi.
The taxi service will be provided in the UK.

If they tell me their flight arrives at 22:25hrs on 23rd of October 2015, I can safely say that date falls within British Summer Time for the year 2015. If they tell me their flight arrives on 4th November 2015, I know that in the UK we would have reverted back to GMT. This is all I need to know!

I am not concerned about what the time is wherever the customer is.

RE: Check if date is BST or GMT, timezone help

I would think that a good place to start might be a web reference like the following - where the Longitude and Latitude values to be used would represent your final location (such as Heathrow - not the current one):
How to get a time zone from a location using latitude and longitude coordinates?
http://stackoverflow.com/questions/16086962/how-to...
which in turn references: General Information About Time Zones
http://stackoverflow.com/tags/timezone/info

Good Luck

RE: Check if date is BST or GMT, timezone help

(OP)
This is depressing. I give up.

RE: Check if date is BST or GMT, timezone help

(OP)
Chris do you at least understand what I'm trying to do now?

RE: Check if date is BST or GMT, timezone help

Quote:

If they tell me their flight arrives at 22:25hrs on 23rd of October 2015

I think you can safely assume that daylight savings time will have already have been allowed for in the timing that airlines provide. So if an airline says 15:30 at Heathrow they ARE ALREADY using whatever local time it is going to be AT Heathrow on that date.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Check if date is BST or GMT, timezone help

(OP)
Chris why are you questioning what I'm doing. It is a requirement of the system I'm using that I must differentiate between the two.

Can you please not respond to my posts anymore. You are reluctant to provide a solution (which is fair enough) but worse than that is that you don't seem to understand what I'm asking plus you are now questioning why I'm asking it in the first place.

You have helped me in the past and for that I'm thankful but on this post in particular you've been a pain the a**!

RE: Check if date is BST or GMT, timezone help

Perhaps this answers your question? :- https://www.gov.uk/when-do-the-clocks-change

The important thing to note is

Quote:

In the UK the clocks go forward 1 hour at 1am on the last Sunday in March, and back 1 hour at 2am on the last Sunday in October.
take your date and do the math.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: Check if date is BST or GMT, timezone help

(OP)
Brilliant.

Thanks so much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close