I have Kendo UI grid when I save a new date value, the value send as POST request like
Wed Jun 19 2013 17:48:32 GMT+0200 (Egypt Standard Time)
I am trying to take this value and send to the web service which waiting value with type "DateTime"
I want to convert the sending value date even in Kendo UI before send as POST value or
in the PHP file when I receive this value
Any Help ?
kendo ui allow set culture and date format adding
please checkout http://docs.kendoui.com/api/framework/kendo#culture
http://docs.kendoui.com/getting-started/framework/globalization/dateformatting
Reading i found this:
http://www.kendoui.com/forums/framework/globalization/kendo-fails-to-parse-or-format-utc-dates.aspx
parameterMap: function (options, operation) {
if (operation != "read") {
var d = new Date(options.Date);
options.Date = d.toString("yyyy-MM-dd");
return options;
}
}
{ field: "Date", title: "Date ", type: "date", format: "{0:dd/MM/yyyy}" }
result : 30/08/2012
kamal , I think this would be the solution and this how I solve it
parameterMap: function (options, operation) {
if (operation != "read") {
//change the fieldDate variable to your field date
var d = new Date(options.models[0].fieldDate);
options.models[0].fieldDate = kendo.toString(new Date(d), "yyyy-MM-dd");
return options;
}
}
it might help someone like me ...
Related
I have a javascript date that I am passing via ajax to a php script then using the date in an sql insert into mysql database. I can't figure out how to format the date so the SQL call accepts it. Can anyone help with this?
In the AJAX call I've tried passing the date object as is, converting to JSON, to UTC.
The error I get is:
Incorrect date value: 'Thu, 01 May 1902 03:01:00 GMT' for column 'uspr_dob'
This all works if I remove the date line from the SQL code. ie I update the other fields but not the date. So everything else is working except the date passing.
jQuery date formation:
var dob = new Date(year, month, day, hours, minutes, 0, 0);
jQuery AJAX call:
var save_result = jQuery.ajax({
url: lb_path + "update_user.php",
data: { 'lb_user_id' : this.id,
'lb_dob' : this.dob.toUTCString(), //toJSON
... },
type: 'POST',
datatype: 'json',
success: function(data, status) {
...
}, // End success
error: function (xhr, ajaxOptions, thrownError) {
...
}
}); // End load the supplement list
PHP code is:
$sql = "UPDATE userpref
SET uspr_person_group = \"".$lb_gender."\",
uspr_diet_type = (SELECT diet_id FROM diet WHERE diet_name = \"".$lb_diet."\"),
uspr_exercise_profile = (SELECT exprof_id FROM exercise_profile WHERE exprof_name = \"".$lb_exercise."\"),
uspr_dob = \"".$lb_dob."\"
WHERE uspr_user_id = ".$lb_user_id;
If you use YYYY-MM-dd format you will never run into any issues. It is better to convert it before passing it to the server in your case.
Please refer to Get String in YYYYMMDD format from JS date object? .
OK - I found the problem - The database documentation showed the field in the table was DATETIME ... when actually it was DATE.
Once I spotted that and massaged the datetime string into MySQL's format it all worked beautifully!
Still I would think that there is an easier way to do this ... ie a date format in javascript that can be passed straight through AJAX, PHP then SQL and work without any formatting.
highcharts gets my hour time wrong
I'm from venezuela just in case. I doing a real time system where I get in my db the time,seconds and miliseconds like
10:39:09:2
I apply the strtotime($time) then I sended by json to charted
and in my highcharts i got in the
xAxis: {
type: 'datetime',
title: {
text: 'Tiempo'
}
the utc function is already false
Highcharts.setOptions({
global: {
useUTC: false
}
});
and my function to get the json is
function requestData_Frecuencia() {
$.ajax({
url: 'Datos_Frecuencia.php',
success: function (point) {
var series = chart_Frecuencia.series[0],
shift = series.data.length > 400;
//add point
chart_Frecuencia.series[0].addPoint(eval(point), true, shift);
setTimeout(requestData_Frecuencia, 500);
},
cache: false
});
}
PS. is been a while since I write in english so forgive me if I write something wrong o that isn't clear.
You should check the raw values in the database. I know that MySQL stores dates in GMT. Not sure about the DB you are using, but the reason that this is done is:
GMT is an absolute time reference & doesn't change with the seasons.
You will have to convert the time to your locale, which is UTC–04:30
Have a look at: Convert date to another timezone in JavaScript
Highcharts doesn't include timezones and only what you can do is disabling UTC,aas you have. THen you need to translate your data or use label formatter / tooltip formatter to display correct data.
I found out what I was doing wrong (found the answer here ). I used to get my time in php like:
while($r2 = pg_fetch_array($sth)) {
$hora = $r2['hora'];
$Frecuencia = $r2['frecuencia'];
}
$x=strtotime($hora);
I needed to multiplied by 1000 the time. I think, is because I need to suggested that date is in form of miliseconds (that is integer)
while($r2 = pg_fetch_array($sth)) {
$hora = $r2['hora'];
$Frecuencia = $r2['frecuencia'];
}
$x=strtotime($hora)*1000;
PD: thanks to everybody anyway for the suggestion and responses given. I really appreciated
I am using a jquery date picker and also setting a date through php date('Y-m-D') functions. Both of them give different date for today. Jquery picker fills the field with the date that is one day ahead of php date(). Here is the function for jquery. I need jquery to show same date for today as php.
<script type="text/javascript" charset="utf-8">
var $j = jQuery.noConflict();
$j(function()
{
// initialise the "Select date" link
$j('#date-pick')
.datePicker(
// associate the link with a date picker
{
createButton:false,
startDate: '01/01/1970',
endDate: (new Date()).asString()
//endDate:<?php echo date('y-m-d'); ?>
}
).bind(
// when the link is clicked display the date picker
'click',
function()
{
updateSelects($j(this).dpGetSelected()[0]);
$j(this).dpDisplay();
return false;
}
).bind(
// when a date is selected update the SELECTs
'dateSelected',
function(e, selectedDate, $td, state)
{
updateSelects(selectedDate);
}
).bind(
'dpClosed',
function(e, selected)
{
updateSelects(selected[0]);
}
).val(new Date().asString()).trigger('change');
var updateSelects = function (selectedDate)
{
var selectedDate = new Date(selectedDate);
if(selectedDate != "Invalid Date")
{
$j('#d').val(selectedDate.getDate());
$j('#m').val(selectedDate.getMonth()+1);
$j('#y').val(selectedDate.getFullYear());
}
}
// listen for when the selects are changed and update the picker
// default the position of the selects to today
var today = new Date();
updateSelects(today.getTime());
});
</script>
jQuery uses the client computer's date while php uses the server's date. They're basically different if you haven't set the default timezone in php. Take a look at this:
http://php.net/manual/en/function.date-default-timezone-set.php
You can set the default timezone in php.ini file located on the PHP main directory (Eg. PHP5.4)
As for the using of the server's date in the datepicker:
A quick google search lead me to this: how to display server side dates in jquery datepicker?
basically what they have done is creating a new date based on the current timestamp:
$timestamp = strtotime("2012-08-02");
minDate: new Date('<?php echo $timestamp; ?>');
DO NOT TRUST THE CLIENTS DATE AND TIME
These values can be altered at a whim.
Just use them on advisement.
Besides Javascript is there to enhance the users experience (i.e. make it more interactive). But at the end of the day you will have to pick up the pieces it you do not validate and verify the data you get from the client
For my Visualization Table, i populated data from server side using PHP as guided by http://code.google.com/apis/chart/interactive/docs/php_example.html. I have two columns with time. Now i given 'string' type to this column and pass 12 hour format time. The response Json draw table properly. But sorting not works properly in 12 hour format.It sorts only depends on first two characters. It does not consider the am , pm.
I want to sort the am,pm time properly.I have tried to pass 24 hour format data from server and receive it javascirpt and try to format the time. But It is also not works properly.Please help me resolve this problem.
function drawTable() {
var username="Raja";
var curdate="19/03/2012";
var jsonData = $.ajax({
url: "cltable.php",
data:{'name':username,'date':curdate},
dataType:"json",
async: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
console.log(jsonData);
var timetabledata1 = new google.visualization.Table(document.getElementById('commontables'));
timetabledata1.draw(data, { 'backgroundColor':'transparent'});
}
My PHP Scritp to populate Data:
$colarray=array(array("id"=>"ent","label"=>"Entry_time","pattern"=>"","type"=>"datetime"),array('id'=>"ext","label"=>"Exit_time","pattern"=>"","type"=>"datetime"));
$table['cols']=$colarray;
for($i=0;$i<$customersnum;$i++)
{
$prefinal[$i]=array("c"=>array(array("v"=>$entry_time[$i]),array("v"=>$exit_time[$i])));
}
$table['rows']=$prefinal;
echo json_encode($table);
I'm trying to create a countdown for an event. I'm using Jquery Countdown
I have this code:
$(function () {
var fecha = new Date("July 30, 2011 00:00:00");
$('#defaultCountdown').countdown({
until: fecha,
format: 'DHMS',
expiryUrl: "http://www.google.com",
serverSync: serverTime,
timezone: -4
});
});
function serverTime() {
var time = null;
$.ajax({
url: 'serverTime.php',
async: false,
dataType: 'text',
success: function (text) {
time = new Date(text);
},
error: function (http, message, exc) {
time = new Date();
}
});
return time;
}
The script is working fine, but when I try to change the clock date, the countdown changes.
Any idea why?
I imagine you created the serverTime.php file on your server?
http://keith-wood.name/countdown.html
Tab Timezones has the PHP code you'll need to add to serverTime.php for your script to use that. Also may want to fully qualify that to something like url: 'http:yourdomain.com/serverTime.php' But using that it should use your server time not your local PC time. If your server is on your local PC, then well... it would change.
I went to their site, with their example, and changing my system time affects their countdown as well. Their code relies on local system times.
What I see when you get the server time form the ajax call, it is not creating the JavaScript date object.
I searched and below worked for me.
// Split timestamp into [ Y, M, D, h, m, s ]
var t = "2010-06-09 13:12:01".split(/[- :]/);
// Apply each element to the Date function
var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
alert(d);
// -> Wed Jun 09 2010 13:12:01 GMT+0100 (GMT Daylight Time)