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

Wednesday, October 5, 2022

[FIXED] How can i change j/M/y date format to timestamp?

 October 05, 2022     date, date-format, excel, php, phpexcel     No comments   

Issue

I tried convert to timestamp but not working, My code is below

$date = $objPHPExcel->getActiveSheet()->getCell('A' . $x)->getFormattedValue();//output value is 9/Feb/16

echo strtotime($date);//return value is empty

It's return empty value. I want to compare Excel sheet date and PHP returned date. Excel sheet returned date is like this -> 9/Feb/16


Solution

If the value in the cell is an MS Excel serialized timestamp, then you can get the "raw" value from the cell

$date = $objPHPExcel->getActiveSheet()
    ->getCell('A' . $x)->getValue();

which should return a number like 42409 for 2nd February 2016

Then use the built-in date/time conversion functions to convert that either to a unix timestamp, or to a PHP DateTime object

$date = PHPExcel_Shared_Date::ExcelToPHP($date); // returns a unix timestamp
echo date('Y-m-d H:i:s', $date);

or

$date = PHPExcel_Shared_Date::ExcelToPHPObject($date); // returns a DateTime object
echo $date->format('Y-m-d H:i:s');


Answered By - Mark Baker
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • 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