i am using bootstrap-datetimepicker.min.js which originally from here (http://tarruda.github.io/bootstrap-datetimepicker/)
when i click some button, the ajax is returning datetime in this format:
Thu Jul 18 2019 07:00:00 GMT+0700 (SE Asia Standard Time)
how to make this format to yyyy-mm-dd so it can fit in mysql database?
i've see some function inside the js file there is formatDate(d) function. But there's no documentation regarding that function..
code for getting the result
var expired_date= $('#dateTimeExpired').data('datetimepicker');
exp_date = expired_date.getDate();
Is there any helps?
thanks in advance.
var dateRaw = "Thu Jul 18 2019 07:00:00 GMT+0700 (SE Asia Standard Time)";
var dateObject = new Date(dateRaw);
var dateFormatted = dateObject.toISOString().substring(0, 10);
alert(dateFormatted); // 2019-07-18
http://jsfiddle.net/eymA4/
Related
I have a problem. I want to convert this DateTime: 2018-10-28 02:00:00 to a TimeStamp. Now the TimeStamp I am looking for is: 1540684800, but with my code I get this TimeStamp: 1540688400. I know it has something to do with my TimeZone, but I don't know how I can fix this.
I live in the Netherlands in Amsterdam.
Here is my code:
$LoopDateTime = "2018-10-28 02:00:00";
$search_key = (strtotime($LoopDateTime)*1000);
Can someone help me?
The time zone identifier for Amsterdam is Europe/Amsterdam and 1540688400 is the correct timestamp. There's surely an online tool to check but you can also verify it from PHP itself:
$date = new DateTime("#1540688400");
$date->setDateTimeZone(new DateTimeZone('Europe/Amsterdam'));
echo $date->format('r'); // Sun, 28 Oct 2018 02:00:00 +0100
However your code is not robust because depends on the configured timezone. You can just set it explicitly in a number of ways, e.g.:
$LoopDateTime = "2018-10-28 02:00:00";
$search_key = strtotime($LoopDateTime . ' Europe/Amsterdam') * 1000;
var_dump($search_key); // int(1540688400000)
Or:
date_default_timezone_set('Europe/Amsterdam');
$LoopDateTime = "2018-10-28 02:00:00";
$search_key = strtotime($LoopDateTime) * 1000;
var_dump($search_key); // int(1540688400000)
P.S. If I'm not wrong Sunday 28 Oct 2018 02:00:00 +0100 is the exact moment when most Europe has just switched from CEST (+0200) to CET (+0100).
I am beginner.
I would like to compare iPhone device Date with my Persian Date Logic.
So, my Date() Function not working on Iphone.
I would like to this normal Date() function fetch iPhone current system date/time. Any function to get iPhone Device Date()?
My code is below.
Thanks for helping me in advance.
function _compareDate(dateString) {
var selectedDate = new Date(dateString);
console.log(selectedDate);
var now = new Date();
if (selectedDate < now) {
return false;
} else {
return true;
}
}
My Now Date Returns: Fri Feb 03 2017 00:00:00 GMT+0530 (India Standard Time)
I've some data from an AJAX call. One of the parts is date. I need the date to be printed in this format:
Date.UTC(YY,MM,DD,hh,mm,ss)
I tried this:
var jsonDate = field.substr(1, field.indexOf(',')-1);
var phpDate = jsonDate.split(/[- :]/);
var jsDate = new Date(Date.UTC(phpDate[0], phpDate[1]-1, phpDate[2], phpDate[3], phpDate[4], phpDate[5]));
But it returns a string and it's in my local time zone.
Something like this:
Mon Jul 13 2015 21:11:05 GMT+0430 (Iran Daylight Time)
I need to convert it to the mentioned format.
You can use toISOString() to convert any date to UTC:
var dt = new Date('Mon Jul 13 2015 21:11:05 GMT+0430 (Iran Daylight Time)');
console.log(dt); // for me == Mon Jul 13 2015 17:41:05 GMT+0100 (BST)
console.log(dt.toISOString()) // == UTC
I would suggest you to use jquery-dateFormat
https://github.com/phstc/jquery-dateFormat
var jsDate = new Date(Date.UTC(2016, 1, 23, 13, 14, 15));
var fromated = $.format.date(Date.UTC(2016, 1, 23, 13, 14, 15), "yy,MM,dd,hh,mm,ss");
console.log("Date.UTC(" + fromated + ")"); //Date.UTC(16,02,23,06,44,15)
my client is proving me with date strings as follows
Tue Nov 30 00:00:00 GMT+0400 1965
how can i insert this format into a postgresql Date column please, or will i have to do it the hard way and use the sub strings to compile a string of
Nov 30 1965
Please can someone help im very stuck for time.
Thanks in advance.
It would be possible for you, if you date have no timestamp in it:
select to_timestamp('Tue Nov 30 00:00:00 1965', 'DY Mon DD HH24:MI:SS YYYY')
So I think you have to make a new from your string:
select
to_timestamp(substring(dt from 0 for 20) || substring(dt from 29), 'DY Mon DD HH24:MI:SS YYYY')
from (select 'Tue Nov 30 00:00:00 GMT+0400 1965'::text as dt) as a
sql fiddle demo
ive managed it this way
function dateStringToDb($dateString){
if($dateString != NULL){
$dateString = substr($dateString,4,6)." ".substr($dateString,sizeof($dateString)-5,4);
return new Zend_Db_Expr("to_date('".$dateString."', 'Mon DD YYYY')");
}
return NULL;
}
this seems to be the best method, thanks anyway
Good !
I am having some difficulties with extracting data from a date. The thing is that I get a number from an undocumented API.
"created": 734394
"last_chapter_date": 734883
I tried dividing it by 365,242 days (exact amount of days a year)
2010,705231052289
So apparently these are the number of days passed since 0.0.0000
I am currently trying something like that:
http://jsfiddle.net/LRUy5/4/
function zero21970(nDays) {
// 0 70 2013
// |-----|-----|
// 0 to date
var dateMils = nDays*24*60*60*100;
// 0 to 1970
zeroTo1970 = (1970*365.242)*24*60*60*100;
//subtract time from 0-1970 from the time 0-date
//to cut out the part from 1970-today
return new Date(dateMils-zeroTo1970);
}
//http://www.mangaeden.com/api/manga/4e70e9f6c092255ef7004344/
zero21970(734394) //-> Jan 26 1974
I need to save it in a database and work with it via php or javascript..
Does anyone recognize this kind of format or do you know a convenient way of formatting it?
Edit: I should add that the last chapter came out around 15.01.2013.. just to have something to grab.
Updated version:
I guess if the last chapter was from 2013, then the value is a number of days from 01.01.0001. So we can update the initial date as well as change setHours to setDate method for more accuracy:
var date = new Date("0001");
date.setDate(734883);
date.toGMTString(); // "Tue, 15 Jan 2013 00:00:00 GMT"
DEMO: http://jsfiddle.net/LRUy5/6/
Old version:
I found one solution that successfully works at my computer:
var date = new Date("0000");
date.setHours(734394 * 24);
date.toGMTString(); // "Mon, 13 Sep 2010 21:00:00 GMT"
DEMO: http://jsfiddle.net/LRUy5/5/
If you're using PHP, then you should replace
return new Date(dateMils-zeroTo1970);
with
return date('Y-m-d', (dateMils-zeroTo1970));