I am trying to read dd/mm/yyyy date from Excel. It is behaving very inconsistently. At times it adds one day more to the actual date in the cell and at times give the correct date.
The code:
$pdiDate_key = array_search('PDI Date',$excel->sheets[0]['cells'][1]);
Based on your code example, I'm going to guess that you're using PHP-ExcelReader to retrieve the dates from Excel. If I'm right, then, well, there is a known error in Excel that PHP-ExcelReader doesn't handle. The "bug" report is here:
SourceForge.net: PHP-ExcelReader: Detail: 2388545 - Wrong Date
The comments at the bottom of that page include code for a function to fix the error.
Related
when using PHP spreadsheet i have the date set in the correct format but when opening in excel i am unable to filter dates by month / year etc. i have to click on each date select the formula bar and press enter. this then allows me to filter the date.
how can i set phpspreadsheet to do set this correctly ?
i have been searching google for a solution. the limited results i have found seem to point to the same way i have implemented this
Any suggestions?
Thanks
We've got a collection of messy data, and trying to unify it.
Lots of services let you type dates out into different formats and they correctly understand them, but cant think what the process is called, or how we could go about doing this in PHP, if there is a library that already provides this.
So we've got time and dates in an old database we've inherited, and trying to clean it up a bit, some of the formats look like
9pm
9:00pm
25th march 2015
its a complete mix and match, does anybody know of any libraries or ways to be able to parse these into a universal format?
the problem here is the information you have is inconsistent! you need to normalize it some way, IT might actually be worth getting into an excel sheet and try to match the date time fields into some kind of regex and filter like that, is probably what i would do, so you can separate the different formats and tackle each format individually.
A program will have to first identify the format you're feeding it and then it will spit out whatever format you want!
you can use this strtotime() PHP with this to turn it into any format
http://php.net/manual/en/function.date.php
I'm having an issue with the FileMaker PHP API. I don't know how to format a time correctly for input into a Time field.
I tried entering a string with the format that the documentation guide says (H:M where H can be 24 hours) and it still doesn't take. I don't know if I'm supposed to change the data type with another function like date() or what.
Edit: A little snippet of code
//Date
if($arrDate!=NULL){
$booking->setField('arrival_date', '07/17/2015');
}
//Time
if($arrTime!=NULL){
$booking->setField('arrival_time', '11:00:00');
}
$savedBooking = $booking->commit();
I replaced the variables for the value fields with what they should be just in case it was something going wrong with them, but it still doesn't work. The date field setting works fine if I comment out the Time section however.
Here's the format that I use:
$booking->setField('arrival_date', date ( "n/j/Y H:i:s A" ) );
If you're interested in adjusting the time, here's a post to checkout: http://timdietrich.me/blog/php-timezone-arithmetic/
Good luck!
I suspect you may have some validation set up on the "arrival_time" time field. What is the error that is returned by the API? It should return an error code that will tell you more.
Also worth mentioning that FileMaker will inherit the date and time settings from your system settings. For example, date formats are different in Europe than they are in the states. But that time value you give looks like it would work, and you only get an error when setting that field, so I would look to make sure the field is defined correctly.
You can also test by putting that value in via FM Pro and see what happens.
I'm an idiot, after hours struggling with this I realized I had put the wrong field name! Thanks for your help guys. A string of H:M worked perfectly.
Timezones and timestamps confuses me so I'm hoping someone can answer my questions :)
Lets say I have a Python script that parses an RSS feed, converts the date value into a timestamp using the following code and stores it in a database:
article_date = parse(article.published).strftime('%s') if hasattr(article, 'published') else round(time.time())
Now when I retrieve that record from the db in PHP, and I run the following code, does PHP assume the timestamp was UTC-0 and automatically offsets the timezone to Eastern time?
date_default_timezone_set('America/New_York');
echo date('Y-m-d H:i:s',$timestamp);
I'm seeing weird issues with my dates, so I'm wondering if someone can help me out with advice on how to properly convert and store rss feed timestamps. I can across this line of code somewhere so should I put this at the top of my script?
os.environ['TZ'] = 'Europe/London'
If you want to set your timezones and keep them aligned in PHP and in Python, then your PHP code is completely correct and for python you need to apply the following:
os.environ['TZ'] = 'America/New_York'
time.tzset()
before you call strftime()
That should make sure you store the time in the same zone you're trying to retrieve it.
Note: tzset() is a Unix-only function.
1) I have been working on fetching data from an excel sheet i can see on a cell written Oct-10 but when i select it i see 10/31/2000 on fx column right at top ,when i fetch data from the .xls sheet using http://phpexcel.codeplex.com library version number 1.7.3 ,it is returning float("40482") ,
can any body tell how to convert it to either 10/31/2000"/"Oct-10 all the cells other than this one are reading correctly so there is no error in code.
2) Also Please tell how can i get a better tutorial for this library as one provided on this site is not very helpful or i am using wrong library.
thanks in advance
See answer to this question Days since 1900
or read section 3.2 (and specifically 3.2.3) in the not very helpful "PHPExcel Function Reference Developer Documentation" which describes exactly how to convert between Excel dates and PHP dates (or PHP date/time objects).
The function you're after is:
$PHPdateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
or
$PHPdateObject = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
There are links to a number of tutorials in a variety of languages on the documents section of the PHPExcel website. And in addition to the documentation, there's plenty of code examples in the /Tests subdirectory of the distribution
Example of returning a PHP date/time object:
include 'PHPExcel.php';
$excelDateValue = 40482.0;
$dateObj = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
echo $dateObj->format('Y-m-d H:i:s');
displays
2010-10-31 00:00:00