Welcome Guest, Not a member yet? Register   Sign In
Change date format
#1

(This post was last modified: 03-24-2020, 05:36 AM by kanhaiyaa.)

Hey there I'm new to this community.
While registering events etc. the date format is yyyy/mm/dd but I want to change this format to dd/mm/yyyy however I am not getting this output, anyone please could min help? sry for my bad english. hindi
Reply
#2

How do I Convert Date Format in PHP
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 03-05-2020, 10:08 AM by vincent78.)

I've created a bunch of DateTime classes:
https://github.com/vmoulin78/concorde/tr...s/datetime

and to use it:
PHP Code:
$dt = new Mysql_datetime('2020-03-24');
echo 
$dt->format('d-m-Y'); 

or:
PHP Code:
$dt = new Mysql_datetime(); //equivalent to $dt = new Mysql_datetime('now'); 
Reply
#4

(This post was last modified: 03-06-2020, 04:53 AM by zahhar.)

Well, you could benefit from built-in Time class in CI4 internalization library rather then invent the week and bring in yet another custom converter:

PHP Code:
use CodeIgniter\I18n\Time;

//read $datetime from DB and convert it to human-readable format
$myTime Time::createFromFormat('Y-m-d H:i:s'$datetime)->toLocalizedString('dd.MM.YYYY HH:mm'); 

Now you can adjust input format in creareFromFormat() first parameter to match your source, and adjust output format in toLocalizedString() parameter to receive desired format with respect to localization settings of your application or even your current user.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB