Need help with month /date script

by 9 replies
11
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
#programming #auto #change #month #or 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.
  • 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'); ?>
  • 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.
    • [1] reply
  • 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.
  • 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
    • [1] reply
    • 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
  • 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.
  • interesting.

Next Topics on Trending Feed

  • 11

    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.