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.
Related
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
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.
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
I have a form which user submits and I get the current time and date in the database and facebook ID of the user as well, As per rule the user can fill the form only once in a week, so if he fills the form on Tuesday, he is not eligible to fill the form unless the week is complete, (Only eligible to complete the form again on next Monday)
I am trying to find some php function for weeks but couldn't get so, Anyone can help me what can be done for this logic?
I have date/time in the db for me.
First, you are basically looking for
$date = "2014-10-13";
$week=date("W", strtotime($date));
or even use it this way
$date = "2014-10-13";
$date = new DateTime($date);
$week = $date->format("W");
( http://php.net/manual/en/function.date.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.
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);