Problema con zona horaria php
Publicado por Francisco (4 intervenciones) el 15/08/2019 17:56:47
Buen día, coloco un nuevo tema ya que mi problema lo busqué y sólo había casos de hace años y no quise re abrir el tema, yo voy empezando con php de hecho utilizo dream weaver pero resulta que hice un formulario el cual debe registrar la fecha y hora en el momento de insertar un nuevo registro, el problema es que salen 2 horas de retraso por la localidad de Los Ángeles, me dijeron que debo establecer la zona a mi ciudad pero no logro conseguirlo, me sigue saliendo el retraso, me pueden orientar? dejo un pequeño formulario de prueba donde esto intentando lograrlo. Por su apoyo gracias.
Nota: Estoy utilizando el comando now() para la fecha y hora actual.
Nota: Estoy utilizando el comando now() para la fecha y hora actual.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php require_once('../Connections/USUARIOS.php'); ?>
<?php
date_default_timezone_set("America/Mexico_City");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO Prueba (ID, NOMBRE, EDAD, FECHA) VALUES (%s, %s, %s, now() )",
GetSQLValueString($_POST['ID'], "int"),
GetSQLValueString($_POST['NOMBRE'], "text"),
GetSQLValueString($_POST['EDAD'], "int"),
GetSQLValueString($_POST['FECHA'], "date"));
mysql_select_db($database_USUARIOS, $USUARIOS);
$Result1 = mysql_query($insertSQL, $USUARIOS) or die(mysql_error());
$insertGoTo = "REGISTRO EXITOSO2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_USUARIOS, $USUARIOS);
$query_Recordset1 = "SELECT * FROM Prueba";
$Recordset1 = mysql_query($query_Recordset1, $USUARIOS) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">NOMBRE:</td>
<td><input type="text" name="NOMBRE" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">EDAD:</td>
<td><input type="text" name="EDAD" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insertar registro" /></td>
</tr>
</table>
<input type="hidden" name="ID" value="" />
<input type="hidden" name="FECHA" value="" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Valora esta pregunta


0