Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Need help with month /date script (https://www.warriorforum.com/programming/765647-need-help-month-date-script.html)

KFranks 13th March 2013 02:14 PM

Need help with month /date script
 
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

Brandon Tanner 13th March 2013 03:31 PM

Re: Need help with month /date script
 
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.

Andrew H 13th March 2013 04:31 PM

Re: Need help with month /date script
 
Quote:

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'); ?>


KFranks 13th March 2013 09:32 PM

Re: Need help with month /date script
 
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.

Brandon Tanner 13th March 2013 11:25 PM

Re: Need help with month /date script
 
Quote:

Originally Posted by KFranks (Post 7853206)
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

KFranks 14th March 2013 01:03 AM

Re: Need help with month /date script
 
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.

Susan Stones 14th March 2013 02:49 AM

Re: Need help with month /date script
 
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

TopOfTheMornin 14th March 2013 02:58 AM

Re: Need help with month /date script
 
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.

Andrew H 14th March 2013 07:41 AM

Re: Need help with month /date script
 
Quote:

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

KFranks 14th March 2013 01:27 PM

Re: Need help with month /date script
 
Quote:

Originally Posted by Susan Stones (Post 7853848)
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


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