相关文章推荐
刚毅的红金鱼  ·  CAST and CONVERT ...·  2 月前    · 
逆袭的电梯  ·  【转】.net core webapi ...·  2 年前    · 
成熟的皮蛋  ·  JavaScript ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams I find on a lot of our servers (operating on Australian time) I need to use: date("d/m/o", strtotime($str)); -> i.e 'o' for the year. niggles Apr 20, 2010 at 1:57 Hi there! I have already tried your solution but does not seems to work. Like I asked on my post, I just need the date in the dd/mm/yyyy format without the time component. Thanks for the help, Best regards! Rui Gonçalves Apr 20, 2010 at 9:09 Which part doesn't work? strtotime("2010-04-19 18:31:27"); returns the seconds since the epoch, 1271716287 (for my TZ). date() takes a format string and an epoch int; the format string tells it what to return, and "d/m/Y" is days as a zero-padded int, months as a zero-padded int, and year as four digits. Since no time parameters are included in the format string (e.g. "d/m/Y h:i:s"), they won't be returned Michael Mrozek Apr 20, 2010 at 14:03 Hi there! I was commiting an error with the application of the suggested solution. It worked just fine! To all others, thanks for the responses. Thanks again for the response! Best regards Rui Gonçalves Apr 21, 2010 at 21:52

If your date is in the format of a string use the explode function

    array explode ( string $delimiter , string $string [, int $limit ] )
//In the case of your code
$length = strrpos($oldDate," ");
$newDate = explode( "-" , substr($oldDate,$length));
$output = $newDate[2]."/".$newDate[1]."/".$newDate[0];

Hope the above works now

Simply Try $date=date('d/m/Y',strtotime($yourdatevariable))

or else you want to convert to d-m-Y Just Simply Edit above d/m/Y with d-m-Y

$source    =    'your varible name';
$date    =     new DateTime($source);
$_REQUEST["date"]    =     $date->format('d-m-Y');
echo $_REQUEST["date"];
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.