Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete firstdigit 0 from date and month

Tags:

Code:

$today_mem = date("d.m");
echo $today_mem; // -> 15.02

I need to transform dates like 15.02 into 15.2, also need to transform for ex. 07.02 into 7.2 and so on every day. So the question is: how to delete firstdigit 0 from date and month. Any short solutions?

like image 434
966p Avatar asked Jan 15 '12 15:01

966p


People also ask

How do you remove leading zeros from a date in Java?

For a Regular Expression approach, you can use: String shipDate = '04/06/2022'; // Option 1: shipDate = shipDate. replaceAll('\\b0(\\d)','$1'); // Option 2: shipDate = shipDate. replaceAll('\\b0',''); System.

How to remove zero in PHP?

Method 2: First convert the given string into number typecast the string to int which will automatically remove all the leading zeros and then again typecast it to string to make it string again.

How do I add leading zeros to a date in Excel?

If you prefer leading zeroes on the month everywhere in windows (like the lower right hand clock) then you can: Control Panel >> Clock, etc >> Change Date, Time or Number Formats... then set the Short Date to MM/dd/yyyy. This also carries over to Excel as the first date format.


2 Answers

You'll want to use:

$today_mem = date("j.n");
echo $today_mem; // -> 15.2

To remove the leading zeros. See more format modifiers at: php.net/date

like image 74
chrisn Avatar answered Oct 05 '22 16:10

chrisn


Use j instead of d and n instead of m:

$today_mem = date("j.n"); 

Reference at the PHP doc site.

like image 39
Jon Avatar answered Oct 05 '22 14:10

Jon