Jump to content

Date condition within If statement


ameisez

Recommended Posts

Hi,I don't know how date is computed in javascript.. can someone please convert my this....If (now is between thursday, 12:30AM, India time zone and thursday, 2:30AM, India time zone )do thiselsedo thisto javascript commands.Actually i need it in javascript and php. If it's possible to have it both here it will be great, otherwise here's the PHP postthanks

Link to comment
Share on other sites

have you read about the date objects for each respective language? Usually, when working with dates, you do operations and comparisons using timestamps, and then if you need to display them, you format them into more 'pretty' dates.

Link to comment
Share on other sites

@ thescientistI don't need to display the dates. I only need this to load different codes based on schedules.Basically this date I mentioned is one of the schedule and I want to start off from that if I can see how it is coded.@ShadowMageI will check on that.Thanks to both of you.

Link to comment
Share on other sites

Hi ShadowMage,I checked the link you gave me and this is what I came up with...Start = Thursday 12:30am = ((getday() = 6) && (getHours() = 0) && (getMinutes() = 30) )End = Thursday 2:30am = ((getday() = 6) && (getHours() = 2) && (getMinutes() = 30) )My problems now are...1. how can I check it with Indian timezone regardless of where the page is being visited?2. how can I put in the the construct of...If (now > start && now < end) meaning If now is between start and end

Link to comment
Share on other sites

right, well you should be able to get a timestamp using the date object. that's your now variable. then you can do the same for your start and end conditions (i.e. getting a timestamp), which means you'll have consistent values to compare with. from there you need a way to get the users current timezone and figure out an offset. I think the PHP date object has better support for timezones. You can always just have a server-side script do all the calculations and return the result to the browser.

Link to comment
Share on other sites

well I assume you are trying to use now as a representation of the current time. Chances you are would be saving that value in meaningful way and then using it in your if/else condition. if you look at the tutorials, you will see javascript has a Date object. When you create an instance of it, you will have access to all sorts of meaningful representations of the current date and time, or now.I would look up the PHP Date object first, and see what kind of support it has for timezones, since it might be easier to do the time conditional and the time zone offset calculations within the same script. Out of curiosity, what is to be executed based on the result of the conditional check? As in, what happens in each case?

Link to comment
Share on other sites

Out of curiosity, what is to be executed based on the result of the conditional check? As in, what happens in each case?
I have video page that I wanted to shift when we have live event. Normally there is video loop playing 24/7 on the same page. What I wanted to do is to automatically embed the live video on cetain schedule.So when i visit the page and there is live event, it will be embeded on the page. Otherwise the normal video will be embeded.thanks
Link to comment
Share on other sites

It sounds like a job for a server-side language. Javascript runs on the client's computer and uses the date on the client's computer.

Link to comment
Share on other sites

have you looked at PHP's date object like I've suggested? I'm not sure what else you're looking from us. Like I said, you can use PHP to figure out the users region/timezone, calculate some sort of offset if necessary, check the current time against the conditions, and then you can either have that executed on page load to show what you want.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...