Solved

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

Posted on 2009-05-13
4
1,033 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now