/    Sign up×
Community /Pin to ProfileBookmark

using date string to open window

Greetings,

Im looking for a script that will get the year, month and day and convert that info into a string as 20050428

Then add on the txt “.htm” to the end and “http://www.mysite.com/lotto” txt to the front, to then open that string in a new blank window as below…

window.open(‘javascript string’,'”_blank”‘);

which the string should actually be…

window.open(‘http://www.mysite.com/lotto20050428.htm’,'”_blank“‘);

Thanks to those

to post a comment
JavaScript

19 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 28.2005 — [code=php]<script type="text/javascript"><!--
var today = new Date();
var year = today.getFullYear()+"";
var month = (today.getMonth() + 1)+"";
var date = today.getDate()+"";
if(month.length == 1)
month = "0"+month;
if(date.length == 1)
date = "0"+date;
str = "http://www.mysite.com/lotto/"+year+month+date+".htm";
window.open(str);
//-->
</script>[/code]
Copy linkTweet thisAlerts:
@ranosbauthorApr 28.2005 — What do you mean by "Please quote my post" ?
Copy linkTweet thisAlerts:
@scragarApr 28.2005 — the forum tend to add space and such, these vanish if you actualy quote my post as opposed to just copying the code from the box(that's a sig, the forum hasn't changed anything this time, but usualy it does).

https://webdeveloper.com/forum/newreply.php?do=newreply&p=359224

simply remove the [/code] and [code=php] tags.
Copy linkTweet thisAlerts:
@KorApr 28.2005 — [code=php]
<script type="text/javascript">
var today = new Date();
var y = today.getFullYear().toString();
var m = (today.getMonth()+1).toString();
if(Number(m)<10){m=0+m}
var d = today.getDate();
if(Number(d)<10){d=0+d}
var sDate = y+m+d;
function openNewWin(){
window.open('http://www.mysite.com/lotto'+sDate+'.htm','newwin')
}
</script>
[/code]
Copy linkTweet thisAlerts:
@CharlesApr 28.2005 — &lt;script type="text/javascript"&gt;
&lt;!--
Date.prototype.toIdString = function () {return [this.getYear(), this.getMonth() &lt; 9 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1, this.getDate() &lt; 10 ? '0' + this.getDate() : this.getDate()].join ('')}

window.open ('http://www.mysite.com/lotto' + new Date().toIdString() + '.htm')
// --&gt;
&lt;/script&gt;
Copy linkTweet thisAlerts:
@ranosbauthorApr 28.2005 — Actually the first one didnt work, this one I made the whole script a function, then called via

<td onclick="openwindow(''); "

</td>


function openwindow(){

var today = new Date();

var y = today.getFullYear().toString();

var m = (today.getMonth()+1).toString();

if(Number(m)<10){m=0+m}

var d = today.getDate();

if(Number(d)<10){d=0+d}

var sDate = y+m+d;

window.open('http://www.mysite/lotto'+sDate+'.htm','_blank')

}

Thanks! It works!
Copy linkTweet thisAlerts:
@KorApr 28.2005 — I guess that Charles variant will work as well, and his code is shorter, as he's a remarcable coder...
Copy linkTweet thisAlerts:
@scragarApr 28.2005 — I've heard somewhere that you shouldn't use the (condition)?true return: false return

thing, I have trouble remembering where though.

I found the problem with mine...

Oh and charles script is great because it uses protype to asign functions and make things better.
Copy linkTweet thisAlerts:
@CharlesApr 28.2005 — I've heard somewhere that you shouldn't use the (condition)?true return: false return[/QUOTE]It is called "the ternary" operator and it is found in several languages, quite usefull and has no drawbacks.

Perhaps there was a particular application where you shouldn't have used it.
Copy linkTweet thisAlerts:
@scragarApr 28.2005 — yeah, I have been reading quite a few manuals for PHP and C++ lately(unfortunatly they both look very similar to javascript)...
Copy linkTweet thisAlerts:
@ranosbauthorApr 28.2005 — Yes Charles is better, and Kors works too! Thanks gents...
Copy linkTweet thisAlerts:
@CharlesApr 28.2005 — Please, it might be that Charles' is better, but I am certain that all the regulars here will join me in insisting that Charles is not better. To the contrary, he is rather less then the rest.
Copy linkTweet thisAlerts:
@scragarApr 28.2005 — charles is right, his is not better, it just uses a different approach to the same problem, if you wanted to edit it you would have slightly more work going through charles' than with Kor's.

but then charles' uses less space and it looks neater.
Copy linkTweet thisAlerts:
@CharlesApr 28.2005 — Mostly I'm just trying to demonstrate the use of the ternary operator and the Object nature of JavaScript. I want people to think more deeply about the structure and beauty of the language.

And one should never use any script that one doesn't fully understand. Stealing is just fine, stealing blindly is an offence.
Copy linkTweet thisAlerts:
@scragarApr 28.2005 — Mostly I'm just trying to demonstrate the use of the ternary operator and the Object nature of JavaScript. I want people to think more deeply about the structure and beauty of the language.

And one should never use any script that one doesn't fully understand. Stealing is just fine, stealing blindly is an offence.[/QUOTE]

do you mind If I reuse that second part in my quote of the day(that isn't realy as I only have 5 or 6 images that are shown on a cycle)?

[img]http://c.1asphost.com/DailyQuotes/img.asp[/img]
Copy linkTweet thisAlerts:
@CharlesApr 28.2005 — I'm afraid that my sense of humor will not allow me to allow you to use it, but I encourage you to steal it.
Copy linkTweet thisAlerts:
@KorApr 28.2005 — If a code is shorter, doing the same thing, is better. On the other hand ternary aproach is less obvious (till u are able to [i]see[/i] it) ?
Copy linkTweet thisAlerts:
@scragarApr 28.2005 — I thought of it, but then I kinda still think that there is some reason that I can't remember why you shouldn't use it(although it works fine on all major browsers)...

I must just be remembering something different, or as charles said it could be the situation in which I wanted to use it)
Copy linkTweet thisAlerts:
@KorApr 28.2005 — 
there is some reason that I can't remember why you shouldn't use it(although it works fine on all major browsers)...
[/quote]


that's why

ternary aproach is less obvious
[/quote]

Most of the time people here are beginers, and a ternary aproach could be weird (same with prototype method), at least for the moment...
×

Success!

Help @ranosb 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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