添加星期数

时间:2016-04-14 13:13:37

标签: php date strtotime dayofweek

我想补充不。星期几。结果应该在日期" Y-m-d"。

在这里," time_take"是来自数据库,这是没有。像1,2,3,5,7等。

  <?php
        $date = $record['Child']['dob'];
        $str = "'+".$Vac['Vac']['time_take']." week'";

        echo date('Y-m-d',strtotime($str,strtotime($date)));                
   ?>

我的结果即将到来&#34; 1970-01-01&#34;

这是数据库中日期的格式。

帮助我。

5 个答案:

答案 0 :(得分:2)

<?php
 $date = "2015-01-01";
 $str = "+".$Vac['Vac']['time_take']." week";
 //echo date('Y-m-d',strtotime("$str",strtotime($date)));
  echo date('Y-m-d',strtotime($str,strtotime($date)));
?>

<强>输出:

2015-01-08

检入在线编辑器。 Click Here

答案 1 :(得分:2)

如果你开始时保持简单,你可以在代码工作后始终连接代码

$dob   = $record['Child']['dob'];
$num   = $Vac['Vac']['time_take'];
$pDate = strtotime("$dob + $num week");
echo date('Y-m-d',$pDate);

答案 2 :(得分:1)

试试这个

$start_date = $record['Child']['dob'];  
$str =  $Vac['Vac']['time_take'];
$date = strtotime($start_date);
$date = strtotime("+".$str." week", $date);
echo date('Y-m-d', $date); 

答案 3 :(得分:0)

在我的代码中进行一些修正后,有2-3个答案帮助。 最后的答案是: -

    <?php
        $date = $record['Child']['dob'];
        $str = "+".$Vac['Vac']['time_take']." week";

        echo date('Y-m-d',strtotime($str,strtotime($date)));                
   ?>

输出正确。

答案 4 :(得分:0)

连接代码后它工作一次。

public Server() throws IOException {
    this.ss = new ServerSocket(this.PORT);
}

@Override
public void run() {

    while(true) {
        try {
            Socket cli = this.ss.accept();
            new Thread(new Hanlder(cli)).start();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
}

class Hanlder implements Runnable {

    private Socket client = null;

    public Hanlder(Socket cli) {
        client = cli;
    }

    @Override
    public void run() {
        BufferedWriter bwriter;
        try {

            InputStreamReader input = new InputStreamReader(this.client.getInputStream());
            BufferedReader buf = new BufferedReader(input);
            String line = null;
            while( (line = buf.readLine()) != null ) {
                System.out.println(line);
            }

            bwriter = new BufferedWriter( new OutputStreamWriter(client.getOutputStream()));
            bwriter.write("HTTP/1.1 200 OK \n"
                    + "Hello, World");
            bwriter.flush();

            this.client.close();

        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
}

输出:

$start_date = $record['Child']['dob'];  
$str =  $Vac['Vac']['time_take']." week";
$date = strtotime($start_date);
$date = strtotime("+".$str." week", $date);
echo date('Y-m-d', $date);