Jump to content

[SOLVED] Removing Zero at Beginning of DATE Minutes


jlp09550

Recommended Posts

also something like this should work....

 

<?php
function shorten_minute($min) {
  return (substr($min,0,1) == 0) ? substr($min,1,1) : $min; 
}

$minutes = "12";
echo shorten_minute($minutes) . "\n";

$minutes = "03";
echo shorten_minute($minutes) . "\n";
?>

Hello again.

 

I can't get them to work. For some reason, it blanks them out.

I have tried both. The second one worked better than the other one, but still failed.

 

The code:

$lastseen_1 = time() - $get_data['lastvisit'];
$minute = date('i',$lastseen_1);
$second = date('s',$lastseen_1);

function shorten_minute($min) {
  return (substr($min,0,1) == 0) ? substr($min,1,1) : $min; 
}

$minutes = shorten_minute($minute);
$seconds = shorten_minute($second);

$comb = $minutes + $seconds;

echo $comb;

 

... which outputs "0".

 

Thanks,

Jared

Where does this come from?

 

$get_data['lastvisit'];

 

 

 

It's a time()

 

This is your problem:

$comb = $minutes + $seconds;

 

You are adding the minutes and seconds together as numbers - not concatenating the strings. Use this:

 

$comb = $minutes .":". $seconds;

 

That is not what I want. I want to remove the zero in the minute/seconds, if there is one.

Where does this come from?

 

$get_data['lastvisit'];

 

 

 

It's a time()

 

This is your problem:

$comb = $minutes + $seconds;

 

You are adding the minutes and seconds together as numbers - not concatenating the strings. Use this:

 

$comb = $minutes .":". $seconds;

 

That is not what I want. I want to remove the zero in the minute/seconds, if there is one.

 

Yes, I understand that. The code you posted works perfectly fine except your are adding the values instead of concatenating them, which is screwing it all up.

 

This:

<?php

function shorten_minute($min) {
  return (substr($min,0,1) == 0) ? substr($min,1,1) : $min; 
}

$lastseen_1 = time() - 2100;

$minutes = date('i',$lastseen_1);
$seconds = date('s',$lastseen_1);

echo "Minutes before processing: $minutes<br>";
echo "Seconds before processing: $seconds<br>";

$minutes = shorten_minute($minutes);
$seconds = shorten_minute($seconds);

echo "Minutes after processing: $minutes<br>";
echo "Seconds after processing: $seconds<br>";
?>

 

Produced this:

Minutes before processing: 09
Seconds before processing: 01
Minutes after processing: 9
Seconds after processing: 1

 

Isn't that what you wanted?

 

However, this works just as well without all the fuss:

$minutes = date('i',$lastseen_1) * 1;
$seconds = date('s',$lastseen_1) * 1;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.