/    Sign up×
Community /Pin to ProfileBookmark

Date passed in URL… Please Help

Im wondering if anyone has a simple solution to do this.

I already have a server side script in place… I want to use a javascript to automatically make the date in an url change

[CODE]timerange=CUSTOM_DATE&startdate_str=[B]Nov-19-2005[/B]%20[B]19[/B]&enddate_str=[B]Nov-20-2005[/B]%20[B]07[/B]&timediv=HH24&[/CODE]

I need the date to be read in the current format…. there is a start date and an end date.

So basically .. what I want … is when you open the HTML page.. it automatically redirects you to an url .. which contains the above code .. except it will automatically use todays date .. the end date is always 12 hours later then the start date. the 19 and the 07 are the clock hours. ie/ 19 = 7pm 07 = 7am

Any help with this is appreciated.

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 25.2005 — so let me see if i understood

You want to redirect a page whithin certain periods of the day? If so, between which hours? The hour must be the user's hour or yours' hour?
Copy linkTweet thisAlerts:
@Dynasty79Nov 25.2005 — This code looks like it will accomplish what you want to do:<script type="text/javascript">

Number.prototype.pad = function()
{
return (this < 10) ? "0"+this : this;
}

var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var today = new Date();
var startDate = [[months[today.getMonth().pad()],today.getDate(),today.getFullYear()].join('-'),today.getHours().pad()].join(' ');

var future = new Date(today.getTime() + 12*60*60*1000);
var endDate = [[months[future.getMonth().pad()],future.getDate(),future.getFullYear()].join('-'),future.getHours().pad()].join('%20');

var url = "timerange=CUSTOM_DATE&startdate_str="+ startDate +"&enddate_str="+ endDate +"&timediv=HH24&";
location.href = url;

</script>
It simply runs the same algorithm twice, the second time using a date that is 12 hours in the future (1000 milliseconds/second * 60 seconds/min * 60 minutes/hour * 12 hours, added to the current time). I don't know the entire URL that needs to be changed; to change it, edit the line beginning location.href ...
Copy linkTweet thisAlerts:
@applauzauthorNov 25.2005 — awesome!


Heres the thing tho ... The end date wont always be 12 hours later.

This is a shift report for a 12 hour work shift.

So if someone that started at 7pm ... opened it at say .. 9pm.... it would display the url with the current date from 7pm to 7am the following 12 hours.

If someone opened it at 9am .. it would display the current date .. from 7am to 7pm
Copy linkTweet thisAlerts:
@Dynasty79Nov 25.2005 — I'm not exactly sure what we're looking at. The difference between the times will always be 12 hours? If so, we simply need to set the hour of the today [font=monospace]Date[/font] to the starting hour of the shift. If that is always 7, that is possible. Otherwise, somehow it has to be declared. We'll have to store the starting hour in a variable.

How do you want that to be determined? We could gab the hour when the page loads, or it could be inputted. You make the choice, then I'll supply the necessary changes.
Copy linkTweet thisAlerts:
@applauzauthorNov 25.2005 — The time will not always be 12 hours later than the time you open the page... the end date will always be either 7am or 7pm ...

Heres an example

If you open the page at 9pm tonight ( Nov 25th ) ... then the start date would be November 25 7pm and the end date would be November 26 7am

That would be the results from a night shift 7pm to 7am ...
Copy linkTweet thisAlerts:
@Dynasty79Nov 25.2005 — So if the time is 12 noon, is the start time 7 am or 7 pm (19) ... I'm a tad bit confused of exactly what you want. What hours should it return 7 am start, and what hours for 7 pm?
Copy linkTweet thisAlerts:
@applauzauthorNov 26.2005 — Yes ... if the time is 12 noon .. then the start time would be 7am ... since you havent crossed the 7pm mark ....
Copy linkTweet thisAlerts:
@Dynasty79Nov 26.2005 — <script type="text/javascript">

Number.prototype.pad = function()
{
return (this < 10) ? "0"+this : this;
}

var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var today = new Date();
if(today.getHours() < 19 && today.getHours() >= 7) today.setHours(7);
else today.setHours(19);

var startDate = [[months[today.getMonth().pad()],today.getDate(),today.getFullYear()].join('-'),today.getHours().pad()].join(' ');

var future = new Date(today.getTime() + 12*60*60*1000);
var endDate = [[months[future.getMonth().pad()],future.getDate(),future.getFullYear()].join('-'),future.getHours().pad()].join('%20');

var url = "timerange=CUSTOM_DATE&startdate_str="+ startDate +"&enddate_str="+ endDate +"&timediv=HH24&";
location.href = url;

</script>
All we did was check the hours beforehand. If the hours were between 7 and 19, the start showed as 7 and the end as 19. Otherwise, it started at 19, and ends at 7 (the next day).
Copy linkTweet thisAlerts:
@applauzauthorNov 27.2005 — PERFECT! ..

Now .. my next question... how could I incorporate some sort of calender on the page ... so that you could manually pick a start date and end date. ? hehe ?
Copy linkTweet thisAlerts:
@Dynasty79Nov 27.2005 — Glad we got what you needed. Now for the calendar:

It depends what kind of output you want. You can display a calendar (monthly, yearly, etc), and do many things with it. You can have the user click on an individual day and store info for that day in a cookie, and any day with saved information will be a different color. You can allow the user to toggle months and years, etc.

What exactly do you want done?
Copy linkTweet thisAlerts:
@applauzauthorNov 28.2005 — a visual calendar would be cool.... ( monthly ) ...
Copy linkTweet thisAlerts:
@applauzauthorNov 28.2005 — .. Here's something else ...

Is it possible to have this page refresh itself every 10 seconds ?

.. not sure how to do it .. since the page calls the url right away. ... how can put a refresh script in this to make the url be refreshed every 10 seconds ?
Copy linkTweet thisAlerts:
@Dynasty79Nov 28.2005 — To refresh itself every 10 seconds:<script type="text/javascript">

function refr() {
// there are other ways, such as the refresh method of the window object, et al.
history.go(0);
}
setTimeout(refr,10000);

</script>
As for the calendar ... I seached http://javascript.internet.com 's selection, and they all pretty much are IE-only, which we shouldn't promote. If you Google for JavaScript calendars, you should be able to some good, cross-browser, calendars that you'd like.
Copy linkTweet thisAlerts:
@applauzauthorNov 28.2005 — This isnt working ... because the initial script calls an URL .. and that URL becomes the site...
Copy linkTweet thisAlerts:
@Dynasty79Nov 28.2005 — I know that. What you'll have to check is the presence of the ending in the URL string, and if it exists, don't reset its location right away, but instead, wait 10 seconds to refresh.
×

Success!

Help @applauz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...