How do I write functions for updating the year, month, and day?

Source: Internet
Author: User
How do I write functions for updating the year, month, and day? It didn't take long for me to get started with PHP. I 'd like to ask you,
There is a data table,
The content of the birthday field is 1989-11-28
The ageyear field is year.
The agemonth field is month.
The ageday field is day

I want to write a statement to read the content in birthday and write it into the fields of year, month, and day.

What is the hybrid write class of this statement?

All in a data table

Even if you execute this function three times separately

Which eldest brother can help write for me?

You can write an SQL statement or PHP execution file. you only need to implement this function. thank you.

In addition, I would like to ask another SQL update statement to update the specified content in a table and change it to other content. for example, I want to change 2 in field 123 to 3. thank you.


Reply to discussion (solution)

Query this table using a select statement to obtain the birthday table ..
$ Birthday = $ row ["birthaday"]
$ Array = explode ("-", $ birthday)
$ Year = $ array [1]
$ Mon = $ array [2]
$ Day = $ array [3]
Update again

Query this table using a select statement to obtain the birthday table ..
$ Birthday = $ row ["birthaday"]
$ Array = explode ("-", $ birthday)
$ Year = $ array [1]
$ Mon = $ array [2]
$ Day = $ array [3]
Update again

Well. This method is good. But how should we execute it? Is it a separate PHP file? And create a new table?

Update data table set ageyear = left (birthday, 4), agemonth = substring (birthday, instr (birthday, '-') + 1, 2), ageday = right (birthday, 2 );

Update tb set field = replace (field, '2', '3 ');

Update data table set ageyear = left (birthday, 4), agemonth = substring (birthday, instr (birthday, '-') + 1, 2), ageday = right (birthday, 2 );

Update tb set field = replace (field, '2', '3 ');

Thanks for the success,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.