By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

if a number is say xx how to make it 20xx, but ignore if it is xxxx?

P: n/a
Ok, I am almost finished with what I was trying to accomplish (pulling
future events from a csv file where the first field is the date). I was
concerned that though I wanted dates entered as mm-dd-yyyy, people often
drop the leading zeros and enter yy. I think I have figured out a way to
cover the leading zeros using sprintf. The problem is now converting
something like 04 to 2004.

This is what I have so far:

<?

$readfile = file("events.txt");

for ($k=0; $k<=count($readfile)-1; $k++) {
$field = split(";",$readfile[$k]);

$date = date("Ymd");

$piece = explode("-", $field[0]);
$day = sprintf("%02d", $piece[1]);
$month = sprintf("%02d", $piece[0]);
$array = array($piece[2], $month, $day);
$c = implode("", $array);
if ($c >= $date) {

print ("$month/$day/$piece[2] $field[1] $field[2], etc.<br>");

}
}

?>

Any thoughts would be appreciated.

Bill
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The Biscuit Eater <Bo*****************@comcast.net> wrote:
Ok, I am almost finished with what I was trying to accomplish (pulling
future events from a csv file where the first field is the date). I was
concerned that though I wanted dates entered as mm-dd-yyyy, people often
drop the leading zeros and enter yy. I think I have figured out a way to
cover the leading zeros using sprintf. The problem is now converting
something like 04 to 2004.

This is what I have so far:

<?

$readfile = file("events.txt");

for ($k=0; $k<=count($readfile)-1; $k++) {
$field = split(";",$readfile[$k]);

$date = date("Ymd");

$c = date("Ymd", strtotime($field[0]));
if ($c >= $date) {


Hi Bill,

Much easier - use strtotime(). See above.

HTH;
JOn
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.