PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

[FIXED] How to convert float to int for date in php using CodeIgniter

 January 30, 2022     codeigniter, php, phpexcel     No comments   

Issue

$row['A'] contains 13/03/2019

PHPExcel_Shared_Date::ExcelToPHP(trim($row['A']));

return float value

But date() function in PHP takes int

date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP(trim($row['A'])));

so it return 0

var_dump(PHPExcel_Shared_Date::ExcelToPHP(trim($row['A'])));exit();

showing result :float(2087015296)

print_r(intval(PHPExcel_Shared_Date::ExcelToPHP(trim($row['A']))));exit();

showing result: 2087015296

print_r(date('Y-m-d',2087015296));exit();

showing result 2036-02-19


Solution

You need to convert $row['A'] data to php acceptable date format,

After that pass it directly to date() function to change it's format in your desired way

echo date('Y-m-d', strtotime(trim(str_replace('/','-',$row['A']))));

Output:-https://3v4l.org/beUIG



Answered By - Anant Kumar Singh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing