[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Auto Change Date Weekly

Posted on 2012-09-04
12
Medium Priority
?
726 Views
Last Modified: 2012-09-08
We have a PHP site where the current process is to manually change the date of when the next posting will occur.  (i.e. "This site will be updated again on Month/Day")

Depending on the page within the site some pages are updated weekly and others monthly.  They are always updated every Monday regardless of the cadence.

Is there a way to automate this?

Thanks in advance.
0
Comment
Question by:JesusSardinas
  • 6
  • 5
12 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38367458
See http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

The PHP strtotime() and date() functions play well together for something like this.  I will test a code snippet for you and post back in a moment.  Best, ~Ray
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 total points
ID: 38367477
See if this makes sense for your needs.
http://www.laprbass.com/RAY_temp_jesussardinas.php

<?php // RAY_temp_jesussardinas.php
error_reporting(E_ALL);

// REQUIRED FOR PHP 5.1+
date_default_timezone_set('America/Chicago');

// WHAT DAY IS THE NEXT UPDATE?
$day = 'Monday';

// FORMAT THE DATE OF THE NEXT UPDATE
$next = date('r', strtotime("next $day"));
var_dump($next);

Open in new window

HTH, ~Ray
0
 
LVL 34

Expert Comment

by:Slick812
ID: 38368508
greetings  JesusSardinas, , I did not understand what you do as an "Updating Process" for the several pages of your site. Changing the Update status "Date" of a page should be linked to the actual event of updating that page, not just rolling over (changing)  the date in an automated process. I believe I would have a data base (or file) read for a page's "date of when the next posting will occur", and when the page contents change when the actual page "Update" happens, then change the database entry for that  "date of when the next posting will occur". If you always do several many pages on the same day, you can have all of those pages read just one database entry, , that is updated with the pages. Just a suggestion, but you could just get the current server time and convert to a date format, test to see if the date listing for "date of when the next posting will occur" is a past date, and then auto change the date listing, But it seems like just reading a database value would be easier.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Closing Comment

by:JesusSardinas
ID: 38378017
Thanks Ray.  I got swamped at work and haven't had a chance to test the code but didn't want to leave this open either so I'm closing it for now and assigning you the points.  I'll test at a later time and advise if I need further assistance.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38378205
Thanks for the points and thanks for using EE.  Please post back if there is anything else I can do to help.
0
 

Author Comment

by:JesusSardinas
ID: 38379374
Ray - the code you wrote is nice but how does it auto update from Monday to Monday?  We don't really need the hour.  What we're looking for is a basic "This site will be updated again on September 10".  On Monday, September 10 it would automatically change to say "This site will be updated again on September 17". Continuing the same pattern week after week throughout the year.

Is that possible?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38379388
The PHP date() function provides almost any format date you can imagine.  I just chose the 'r' formatting character because it was easy.  
http://us2.php.net/manual/en/function.date.php

Try this formatting on line 11 of the snippet:

$next = date('F j', strtotime("next $day"));
0
 

Author Comment

by:JesusSardinas
ID: 38379453
Ray this code is perfect.  I tried playing with it a bit to remove the "string(12)" along with the "" around the date but can't seem to figure that out.  What's the easiest way of accomplishing this?

Thanks again for your support!!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38379518
var_dump() is just a data visualization tool.  You may want to use echo, like this:

echo $next;

To get a foundation in how PHP works, this is a really good book:
http://www.sitepoint.com/books/phpmysql5/

All the best, ~Ray
0
 

Author Comment

by:JesusSardinas
ID: 38379623
Thanks for the book reference and your guidance.  Exactly what I needed on all fronts.

Wish I could give you 10,000 points!
0
 

Author Comment

by:JesusSardinas
ID: 38379656
Ray is there a way to have this echo the date 4 Mondays from now?  So instead of it saying September 10 it would say October 8?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38379795
Yes, but 4 Mondays from now appears to be October 1, not October 8.

<?php // RAY_temp_jesussardinas.php
error_reporting(E_ALL);

// REQUIRED FOR PHP 5.1+
date_default_timezone_set('America/Chicago');

// WHAT DAY IS THE NEXT UPDATE?
$day = 'Monday';

// FORMAT THE DATE OF THE NEXT UPDATE
$next = date('r', strtotime("+ 4 $day" . 's'));
var_dump($next);

Open in new window

Best regards, (and buy that book!) ~Ray
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question