Insert float to date field mysql [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am reading an excel file by php and when I get date, php script reads 41850 instead 09/09/2014. I need to save that in my mysql table as date format.
What is the best way to convert it?

If you're using the PHPExcel library, then you use PHPExcel's built-in functions to do the conversion
$unixTimestamp = PHPExcel_Shared_Date::ExcelToPHP(41850);
echo date('Y-m-d', $unixTimestamp);
and
$dateTimeObject = PHPExcel_Shared_Date::ExcelToPHPObject(41850);
echo $dateTimeObject->format('Y-m-d');
will convert the date to a unix timestamp value (that you can then format as you wish using date()) or to a PHP DateTime object respectively
However, if you're reading the cell value using getValue(), try using getFormattedValue() instead... unless you've set read data only to true when you loaded the file, then this will returna formatted string with the date value as it is displayed in Excel

Related

How do I convert DateTime from yyyy-mm-dd hh:mm:ss to yyyymmddThhmmssZ in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to convert a given date and time in format ( yyyy-mm-dd hh:mm:ss ) to (yyyymmddThhmmssZ) in php. For example: 2020-07-30 18:30:00 should be 20200730T183000Z. I also want to know if there are any existing/in-built methods to accomplish this?
As others have said in your comments, you can simply do this with the DateTime object
Here's an example:
$date = '2020-07-21 18:50:32';
$obj = new \DateTime('#' . strtotime($date));
echo $obj->format(DATE_RFC3339); // 2020-07-22T01:50:32+00:00
If RFC3339 isn't your preferred format, feel free to pick one from the manual, or build your own
Try it out: http://sandbox.onlinephpfunctions.com/code/3246477b676e17022da799697acf4df375e1fe08

PHP: How to convert a partial date (dd-mm) to time? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I got this .csv file where I have employee number, name and birthday. Birthday comes in dd-mm format (I live in Mexico), how can I convert it to proper date, so I can call date function date('y-m-d', $date) in order to store it in the database?
You can't! At least not reliably. A date must contain the year.
Consider this example:
$dt = DateTime::createFromFormat('d-m', '29-02');
echo $dt->format('Y-m-d'); // 2019-03-01
If an employee's birthday is on the 29th of February and you store it in DB as Date then you are loosing information. To keep the original information intact you need to store it in the format you have received it in, as a VARCHAR field of suitable length.

Store time in database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Which is the best way to store data which come from the entire world?
I was thinking, for instance, to store the time() without timezone and then convert it every time.
Could be right? Is there a method to detect timezone of a request?
For that you can save a Unix Timestamp in your database.
http://php.net/manual/en/function.time.php
http://dev.mysql.com/doc/refman/5.5/en/datetime.html
Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
So every people have the same timestamp format without a timezone.
Otherwise you have to store a Datetime field and the Timezone and calculate the correct value.

storing Time and Dates into an SQL database using php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How do I store dates and time from an online form I have into an SQL database using PHP? The date/time function is working quite ok.
You should use the datetime datatype for your requirement. It will store both the date and time from your input field based on your query.
For retrieving the datetime you can use the mysql's date_format() function or PHP's date() function. The datetime will always be stored according to the server's time and not on the clients time.

In what date format does the mysql date datatype return data? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
So, I have a date stored in MySQL with the date datatype and when I come to calling
echo $row_myRecordset['date']; // dreamweaver generated
in which date format will it return the date (eg. yy-mm-dd) so I can use it with moment.js?
It is yyyy-mm-dd, e.g. 2013-07-21 (see the MySQL reference)
It will return YYYY-MM-DD with the date datatype
Should be YYYY-MM-DD hh:mm:ss
see: http://cookbooks.adobe.com/post_Format_dates_stored_in_MySQL-16641.html
First of all, what is moment.js the type of tuple used for mySQL to represent the date is of type DATE. You could read on the MySQL documentation here
All depending on how you are getting the data back from the page you can manipulate the data to format it however you want it, hence that "special" formatting that could be applied in that Javascript file moments.js. So if I don't see how you manipulate the date in that specific file, I can't really help you. Please post some code.
Also : This shows lack of research ! Look at this Link
explained here on stackoverflow.com

Categories