?
Solved

Function to convert 'd-m-Y' date to crontab format (* * * * *)

Posted on 2009-05-13
4
Medium Priority
?
1,041 Views
Last Modified: 2012-05-06
Hi
Has anyone got a function to convert dates in 'Y-m-d' or 'd-m-Y' format to the crontab format * * * * *  ?
Thanks
tr5
0
Comment
Question by:tr5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 24373152
It's just

function crontabtime($datestr) {
list($y,$m,$d) = explode('-', $datestr);
if ($y > 31) list($d, $,m, $y);
return "0 0 $d $m *";
}

Not possible to use year
0
 
LVL 7

Expert Comment

by:Jonah11
ID: 24373235
hi hernst,

can you explain what is happening in this code:

if ($y > 31) list($d, $,m, $y);
return "0 0 $d $m *";

what is the significance of 31?  also, i've never seen list() used when it was not followed by an "=" sign.  can you explain your usage above?

thanks,
jonah
0
 
LVL 18

Accepted Solution

by:
Hube02 earned 2000 total points
ID: 24373286
You could also try the following:
$date = '2009-10-21';
$date = date('i H d m w', strtotime($date));
echo $date;

Open in new window

0
 

Author Closing Comment

by:tr5
ID: 31580890
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 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