storing Time and Dates into an SQL database using php [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
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.

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

How to implement time ago like facebook [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 7 years ago.
Improve this question
Can anyone explain me the concept of implementing time ago like facebook
in php. I dont want code. I want to know the flow like database field type, whether to use UTC time stamp and to convert to local time.
Thanks
It is all about your users location. If you have users only at a single timezone, then no need of conversion. But if your users are at different time zones, then you require a conversion.
In the second scenario, covert and save time in DB as UTC, then according to each user location, convert time during fetch.

Display data from Mysql based on date [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 7 years ago.
Improve this question
I am making a table to display data from a MySQL database, this table will display all the information for the current date but next day it will be blank again and contain no information so you can see the information only for the current day, the data will exist in the database forever however and all data can be displayed upon request!
Now you know my goal i will present the problem, i dont know how to display information for only the current day in the table.
Use data_date=CURDATE() in where condition of your select statement. data_date is your date field separating data for each date...e.g
select * from mydata where data_date=CURDATE()
this will only give the current date data as required
A quick search will bring up similar questions, with answers.
However you can use PHP's date() formatter.
Similar question

Insert float to date field mysql [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
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

epoch time with decimals is wrong [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 9 years ago.
Improve this question
A third party API is outputting: "1373762187.198" as a valid date time.
When passed through PHPs date function, I get todays date even though I know the object its attached to is over a week old.
Any ideas how todo a correct conversation?
Just strip the decimals away with an integer cast and then pass it to date (or do you need the milliseconds?)
date("...", (int)$date);

Categories