I would like to insert some excel data in range of 21 days (from day 1 until day 21)into database. Use in PHP coding :)
Can anyone give me a helping hand ,
1) If it is the first time insert excel data into the database table, the data are the whole date in excel column, after that the database will check if table is NOT empty, it will just update the data.(Will this be possible?)
2)Lets for example : $today is 06/24 , the first day in excel file, it will only insert the whole data into database from excel file although the rest of data inside the excel column are empty. While if 06/24 is the 10th day in excel file, the database will only update data on 06/24.
thanks~
You can do this using php ExcelReader. It return all data in array after that you can insert it according to date rage (If exists then update otherwise insert) in your database easily. Find below link to download ExcelReader.
http://code.google.com/p/php-excel-reader/downloads/list
Related
When I try to insert a row in a table in phpmyadmin, that has a date column with the format 'yyyy-mm-dd', it will show up like this:'0000-00-00'. What should I do?
First, I wanted to change the date format, but I gave up on that. Now, I'm focusing on trying to insert my data in phpmyadmin.
I need to import attendance reports to my system using Laravel Excel Library, But I have some problem with the wrong data validation. For example, I have the following excel data that I want to import into my database.
As you can see John has put his finger three times into the machine, But I want to Insert only the first and last record into my database using Laravel excel library. And also the struct of my database is like the following picture.
As you can see In my DB structure I have time_in and time_out in the same row, but in the excel file time _in is in one row, and time_out is in another row, So how I can insert this excel file correctly in my Database.
You need to parse the data before sending it to the Database (DB), not just directly feed it to your DB.
A simple explode with ' ' as the separator can split the Date/Time column then use DateTime to format the date and time, meanwhile keep tracking which of the data you need as Time In and Time Out
Assuming:
$date = explode(' ',$dateTime);
$date[0] = the date, 2/1/2021
$date[1] = the time, 7:31
Assuming the date is j/n/Y,
attendance_date can be filled as $attDate = date_format(DateTime::createFromFormat('j/n/Y', trim($date[0]),'Y-m-d');
may be you have to parse data before store it into database
or your can change the Excel file contents
I'm having some troubles dealing with Timestamp data type in MySQL.
I'm saving simple records in my database using a simple DB structure, like:
ID int
Name varchar
Date timestamp
Text varchar
And then retrieve them with something like:
SELECT * FROM table WHERE Date BETWEEN '2013-01-01' AND '2013-06-30'
Everything works fine if I store records letting MySQL fill the Date field with the actual timestamp, for example: 2013-10-04 22:40:02 which means I don't add any value to the Date field in my INSERT query.
But I need to be able to add the date by my self since my application needs to store the date from where the application started, and not the date and time in which the query was sent to the database.
So what I do is I create the same date/time format my Date field uses which is 2013-10-04 22:40:02 and then do a simply insert:
INSERT INTO table (Name, Date, Text)
VALUES ('Peter', '2013-10-04 22:40:02', 'Hello...')
Now, doing it this way I'm unable to bring any result by date using a select query like this one:
SELECT * FROM table WHERE Date BETWEEN '2013-01-01' AND '2013-11-30'
Even if I try to sort results by Date using PHPMyAdmin interface, all the records that contain manually added dates disappear. If I sort them by ID, they re-appear. I checked and the dates and formats are correct. So I have no idea what the problem could be. I'm new at MySQL by the way.
Hope you can give me a hand. Thanks!
Well, I think I found the problem and it has nothing to do with PHP and MySQL, the problem is that I generate the date with JavaScript, and it's giving the wrong month.. :/
Thanks to everyone anyway!
I am facing a problem, i need to upload a csv file with few columns in it including date time column into database. while uploading the data by reading each row and inserting into database it is working fine with date and time. but when i use load infile the whole date and time appears in database column of the table as 0000-00-00 00:00:00 the data type is date. and i am writing the data & time in csv file in the same format $date = date("Y-m-d h:i:s"); using php. what might be the reason?
I've created a PHP script that parses an HTML page, creates a MySQL query, and inserts the parsed data into a MySQL table. Everything works fine, except for one thing : the date field. When PHP runs the MySQL statement, the dates in the table read 0000-00-00 . If I echo the MySQL query, it results in the following :
INSERT INTO dispatch_table (dispatch_date, dispatch_time, dispatch1, dispatch2, dispatch3, dispatch4, dispatch5, dispatch6, dispatch7, dispatch8, dispatch9, dispatch10, dispatch11, dispatch12, dispatch13, dispatch14, dispatch15, dispatch16)VALUES ('2010-02-02', '10:46:17', '31.90' , '32.15','32.24','32.39','33.46','35.18','39.33','39.39','40.92','41.79','41.82','44.35','45.47','46.89','47.13','67.59');
If I copy and paste the statement into the MySQL table, it inserts the date just fine, but when PHP trys to insert it, I am given all 0's. The dispatch_date field is a "date" field in MySQL. Before inserting the dates with the PHP code, the date to insert is converted to a string (I thought this might solve my problem). Can anyone give me any insight on this?
From tizag.com
When you enter dates that are out of
the range or in the wrong format for a
given date type, MySQL will often just
enter in the default value of all
zeros.
You are storing them in the wrong format.
2010-02-02 (%Y-%m-%d) is the default format but it can be changed. Run this query to learn what the values are in your server:
SELECT ##date_format, ##datetime_format;
If they don't match, you'll have to either change your queries or change the ##date_format and ##datetime_format variables. They can be changed in a per-session basis:
SET ##session.date_format='%Y-%m-%d';
SET ##session.datetime_format='%Y-%m-%d %H:%i:%s';