Getting day, month and year apart from Db |
Dear all.
I want to select the day, month and year from a SQL date field, so with the structure as 2018-03-09. To keep using that example, I want to do this: select the day (= 09), the month (= 03) and the year (=2018) apart from eachother, so that I can edit them without having to edit the entire field. I want to do that, because I want to echo the values as a value in a text form field... I hope someonecan help me with this problem. Thanks in advance.
I store dates in the db as UNIX timestamps, this way it's easy to change the value.
You can then format the timestamps to a human readable date, this might help https://stackoverflow.com/a/29481073 . Use Code: <input type="date" ...>
I use a helper function of my own for this purpose.
Code: function date_parts_iso($date) { Here it is a quick test: Code: list($year, $month, $day) = date_parts_iso('2018-03-09');
03-12-2018, 01:20 PM
(This post was last modified: 03-12-2018, 01:21 PM by ivantcholakov. Edit Reason: single quotes )
If you want to use what is built in PHP, have a look at http://php.net/manual/en/function.date-p...format.php
An example: Code: $date_parts = date_parse_from_format('Y-m-d', '2018-03-09');
If you are obtaining your date from a database query, why not split your date with the query. MySQL has date functions for this case.
Start here https://www.w3resource.com/mysql/date-an...nction.php E.g. SELECT YEAR( '2009-05-19' ) AS yr -> will give 'yr' as 2009. Replace the date with the appropriate field.
I found a solution in the first message. Thank you very much for all the help!
I got very nice information of you ![]()
The following expressions return the day for each date in the input port
GET_DATE_PART ( DATE_SHIPPED, 'D' ) Get month from a date GET_DATE_PART ( DATE_SHIPPED, 'MM' ) Get year from a date GET_DATE_PART ( DATE_SHIPPED, 'Y' ) |
Welcome Guest, Not a member yet? Register Sign In |