Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Obciąć 0 w miesiącu
Kozo_WSP
post
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 9.02.2007

Ostrzeżenie: (0%)
-----


Czy da się obciąć zera w miesiącach < 10?

tzn zamiast styczeń 01 żeby było 1?

Przypominam, że operujemy na dacie nie na stringu.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


Data to też string (IMG:style_emoticons/default/smile.gif)

  1. function tnij_mnie_mocno($int) {
  2.  
  3. return ($int < 10) ? substr($int, 1,1) : $int;
  4. }
  5.  
  6.  
  7. $date = date("Y-m-d");
  8.  
  9. $exp = explode('-', $date);
  10.  
  11. $m = tnij_mnie_mocno($exp[1]);
  12. echo $exp[1].' => '.$m;
Go to the top of the page
+Quote Post
karakara
post
Post #3





Grupa: Zarejestrowani
Postów: 71
Pomógł: 6
Dołączył: 22.09.2012

Ostrzeżenie: (0%)
-----


http://php.net/manual/en/function.date.php

Cytat
m - Numeric representation of a month, with leading zeros - 01 through 12
n - Numeric representation of a month, without leading zeros - 1 through 12
Go to the top of the page
+Quote Post
irmidjusz
post
Post #4





Grupa: Zarejestrowani
Postów: 279
Pomógł: 60
Dołączył: 25.02.2012

Ostrzeżenie: (0%)
-----


a jeśli już usuwać zera z lewej strony, to po prostu:
  1. ltrim($date, '0')
Go to the top of the page
+Quote Post
erix
post
Post #5





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




No to skoro masz pewność, że miesiąc jest dobrze zwalidowany, to wystarczy zrzutować numer miesiąca na inta.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.09.2025 - 19:58