Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 13th Mar 2013, 02:14 PM   #1
Warrior Member
War Room Member
 
Join Date: 2013
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default
Need help with month /date script
Share on: 
fb share twitter share gplus share more share

I used to have the below script imbedded on my sales page so that the date and time would change everyday at midnight. But when I change to wordpress the script wont function anymore. I have been manually changing the date everyday for the past two years but its starting to get to be a pain in the butt. I've procrastinated long enough and need to get this script compatible for wordpress

What kind of script do I need to work in wordpress and where can I get someone to make one. I'm guessing to only take about 5 minutes to write it out.

<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var montharray=new Array("January","February","March","April","May"," June","July",
"August","September","October","November","Decembe r")
document.write(""+montharray[month]+" "+daym+"")
</script>

Thanks
KFranks is offline  
Unread 13th Mar 2013, 03:31 PM   #2
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

Good grief... that's a lot of code just to display the current date!

You can do the same thing with just 1 line of PHP...

PHP Code:
<?php echo date('F jS, Y'); ?>
The above code would display the date in this format --> March 13th, 2013. If you want it in a different format, then check out the 'reference' section of this page.


Brandon Tanner is offline  
Unread 13th Mar 2013, 04:31 PM   #3
Web Developer
War Room Member
 
Andrew H's Avatar
 
Join Date: 2012
Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

Good grief... that's a lot of code just to display the current date!
My thoughts exactly. If you insist on doing it with JS check out this link: JavaScript Date Object

The best way to do it is as Brandon has showed. As a side note, this is how websites display the current year for copyright:

PHP Code:
<?php echo date('Y'); ?>

"You shouldn't come here and set yourself up as the resident wizard of oz."
Andrew H is offline  
Unread 13th Mar 2013, 09:32 PM   #4
Warrior Member
War Room Member
 
Join Date: 2013
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

that is the format I want however JS does not work in my wordpress I put in Brandon script it it did the same thing as my script which was nothing. Nothing shows up. I need some other type of language that works in wordpress.
KFranks is offline  
Unread 13th Mar 2013, 11:25 PM   #5
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

Originally Posted by KFranks View Post

I need some other type of language that works in wordpress.
lol. WordPress is built on PHP!

If you don't know how to insert PHP code into WordPress pages, then maybe this will help...

WordPress › Allow PHP in Posts and Pages « WordPress Plugins

And just for the record, Javascript works in WordPress too...

http://codex.wordpress.org/Using_Javascript


Brandon Tanner is offline  
The Following 2 Users Say Thank You to Brandon Tanner For This Useful Post:
Unread 14th Mar 2013, 01:03 AM   #6
Warrior Member
War Room Member
 
Join Date: 2013
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

Hi again Brandon. Ok I guess I'm doing something wrong. I'm taking the script you gave me, going on the page I want to edit and then clicking the html tab. I then paste that script and hit update. But then when I view the page in the browser there's no date.

I looked at that plug in but it does away with html and I'd have to go over to BBcode. I know hot to write html and I don't want to redo the whole page in BBcode. Not to mention I don't like using plug-ins for minor things like this.

Since wp is written in php why cant I just insert the script you gave me into the page and it work? lol

What do I need to do? This is basically why I have procrastinated doing this for 2 years because I knew it was going to be some pain in the ass thing that took me hours and hours of time to for just one little thing. I've been sitting here for 3 days 24 hours a day trying to figure this out reading and reading, trying things and I can't get it. I've spent more time over the last 3 days then when I add up the 2 minutes a day for the last 2 years to change it manually at 12am everyday. 2 minutes a day everyday for the last 2 years works out to a total of 24.3 hours total time. I have already tripled that time trying to figure out a way to have it done automatically.
KFranks is offline  
Unread 14th Mar 2013, 02:49 AM   #7
Active Warrior
War Room Member
 
Join Date: 2009
Location: NSW, Australia
Posts: 60
Thanks: 0
Thanked 9 Times in 9 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

Normally in WP the line of PHP code would go in the template for the page, post or whatever you are working on. . Where are you placing it?

Putting that code in the post edit box results in it being commented out, which is why you see nothing. So you need to find a way around that. If you don't like the plugin suggested by Brandon have a look at this one
WordPress › PHP Code for posts « WordPress Plugins
Susan Stones is offline  
Unread 14th Mar 2013, 02:58 AM   #8
Active Warrior
War Room Member
 
TopOfTheMornin's Avatar
 
Join Date: 2012
Location: Tennessee
Posts: 38
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

As stated, it all depends upon where you are putting it. For example, if you are putting it in a footer, you could make a child theme, copy over footer.php into your child theme, and then add the PHP code to the footer.php in the child theme.

How to Drive Traffic To Your Website
Free + Paid Reports & Training Courses

SEOalaCarte.com
********************
Cheers, Jonathan Sherman
TopOfTheMornin is offline  
Unread 14th Mar 2013, 07:41 AM   #9
Web Developer
War Room Member
 
Andrew H's Avatar
 
Join Date: 2012
Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

I've been sitting here for 3 days 24 hours a day trying to figure this out
interesting.

"You shouldn't come here and set yourself up as the resident wizard of oz."
Andrew H is offline  
Unread 14th Mar 2013, 01:27 PM   #10
Warrior Member
War Room Member
 
Join Date: 2013
Posts: 8
Thanks: 6
Thanked 0 Times in 0 Posts
Default
Re: Need help with month /date script
Share on: 
fb share twitter share gplus share more share

Originally Posted by Susan Stones View Post

Normally in WP the line of PHP code would go in the template for the page, post or whatever you are working on. . Where are you placing it?

Putting that code in the post edit box results in it being commented out, which is why you see nothing. So you need to find a way around that. If you don't like the plugin suggested by Brandon have a look at this one
WordPress › PHP Code for posts « WordPress Plugins
Yes I was putting it in the post under the HTML tab not the Visual tab. I need the date in about 3 different places of my text. I am using it something like this:

"You arrived at this page in time for my special offer. Through March 14th 2013 I've lowered the price to $27. If you sign up after this date blah blah blah..."

"Sign up now for just $47 ($27 thru March 14th 2013)"

etc etc
KFranks is offline  
Closed Thread


Bookmarks

Tags
auto, change, month, or date, script


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 10:25 AM.