Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1051
  • Last Modified:

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

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
tr5
Asked:
tr5
1 Solution
 
hernst42Commented:
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
 
Jonah11Commented:
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
 
Hube02Commented:
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
 
tr5Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now