Posts o[bootstrap+mysql+php] datetimepicker
Post
Cancel

o[bootstrap+mysql+php] datetimepicker

reference http://www.malot.fr/bootstrap-datetimepicker/

[–READ_RECORD.html–]

**PHP+TSQL : //DATE_FORMAT(meeting_datetime,’%d-%m-%Y %H:%i’) - 24h format

1
2
3
4
5
6
7
<?php $row="null;" read="" specific="" record="" date_format(meeting_datetime,'%d-%m-%y="" %h:%i')="" -="" 24h="" if="" (isset($_get["id"]))="" {="" $find_sql="SELECT client_id, DATE_FORMAT(meeting_datetime,'%d-%m-%Y %H:%i') as meeting_datetime FROM clients where client_id = :id" ;="" $stmt="$db-"?>prepare($find_sql);
	$stmt->bindValue(':id', $_GET["id"]);

	$stmt->execute();
	$row = $stmt->fetchAll();
}
?>

**JS - jQuery Init Datetime Control :

1
2
3
4
5
6
7
8
    $('[name=meeting_datetime]').datetimepicker({
		weekStart: 1,
		todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 1
    });

**JS - Set Datetime Control :

1
2
3
    //set to JS variable the PHP variable as JSONarray!
    var jArray = ;
    $('[name=meeting_datetime]').val(jArray[0]["meeting_datetime"]);

**HTML

```js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
```

<span style="color: #ff0000;">**[--SAVE_RECORD.php--]**</span>

```js
<?php $meeting_datetime="null;" if="" (!empty($_post['meeting_datetime']))="" {="" convert="" html="" control="" 24h="" date="" -="" to="" php="" 24h="" format="" date="" $dt="DateTime::createFromFormat('d-m-Y" h:i',="" $_post['meeting_datetime']);="" set="" to="" variable="" a="" string="" date="" formatted="" as="" mysql="" likes!="" $meeting_datetime="$dt-"?>format('Y-m-d H:i:s');
}

    $sql = "INSERT INTO clients (meeting_datetime) VALUES (:meeting_datetime)";
    $stmt = $db->prepare($sql);
    $stmt->bindValue(':meeting_datetime' , $meeting_datetime); //$_POST['meeting_datetime']);
    $stmt->execute();
    $res = $stmt->rowCount();

if($res == 1)
    //record saved
else
    //error?
```

where the datetime field is nullable :
```js
CREATE TABLE clients (
  client_id int(11) NOT NULL AUTO_INCREMENT,
  meeting_datetime datetime DEFAULT NULL
  PRIMARY KEY (client_id)
)
```

![](https://www.pipiscrew.com/wp-content/uploads/2014/09/snap036.png "snap036")

origin - http://www.pipiscrew.com/?p=1381 bootstrapmysqlphp-datetimepicker

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags