根据当前日期提交表单时,在phpmyadmin数据库中插入周数

根据当前日期提交表单时,在phpmyadmin数据库中插入周数

问题描述:

I want to upload current week number in the database without showing it anywhere in the site when users submit a form. Although I do want to use the week number later to show "Winners of week XX" (main reason I want it uploaded to database). At this time I have created a form which does not refresh the page when submitted to the database. In phpmyadmin I have created a field called Week with type INT. If needed I can of course change this according to working code suggestions. I have spent the last 2 days searching the web and trying to make this work, but finally I decided to join the community and ask about it here. Any suggestions?

Do tell if anyone need me to specify some code. At this time I'm working with script in the index.html and PHP in a separate file.

Problem solved: $weekNumber = date("W"); worked like a charm.

我想在用户提交表单时在数据库中上传当前周数而不在网站中的任何位置显示。 虽然我确实希望稍后使用周数来显示“XX周的获胜者”(我希望它上传到数据库的主要原因)。 这时我创建了一个表单,在提交给数据库时不会刷新页面。 在phpmyadmin中,我创建了一个名为Week的字段,类型为INT。 如果需要,我当然可以根据工作代码建议进行更改。 我花了最近两天的时间在网上搜索并尝试完成这项工作,但最后我决定加入社区并在此处询问。 有什么建议吗? p>

确定是否有人需要我指定一些代码。 这时我正在使用index.html中的脚本和PHP在一个单独的文件中。 p>

问题解决了:$ weekNumber = date(“W”); 像魅力一样工作。 p> div>

You can get week number by php function date as below and can insert it in DB as per your requirement.

$weekNumber = date("W"); 

Try this in your php:

$ddate = "2012-10-18";
$date = new DateTime($ddate);
$week = $date->format("W");
echo "Weeknummer: $week";

It will display-> Weeknummer: 42