How to compare Iphone system Device Date with PersianDate? - php

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)

Related

Bootstrap Datetimepicker JS Format Date Output

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/

Unrecognized Date format

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));

Check if date is before or after a certain date in the same month

I am developing a web app using PHP (Codeigniter).
When a user makes a request for a certain resource in the app I need to check if todays date is before or after the 25th of this month. How can I do this? I do not know how to do it.
This should do it...
if ( date('j') < 25 ) {
// date before 25th
}
You can use the date function with the j format type for that
if (date('j') > 25) {
// It is after the 25th
} elseif (date('j') < 25) {
// It is before the 25th
} else {
// It is the 25th
}
See http://php.net/manual/en/function.date.php for more info

Why do I get the wrong date?

I currently have this method:
function fill_date_jaarlijks()
{
var today = new Date();
$("#datepicker_eind").datepicker("setDate", new Date(today.getFullYear()+1,today.getMonth(),today.getDay()));
}
What it should do is, return the date of (today + 1 year).
What it actually returns is 01 December 2012, while today's date is 19 December 2011.
Could someone explain?
getDay returns day of week
Use getDate instead.
Or better still:
var dateValue = new Date();
dateValue.setFullYear(dateValue.getFullYear() + 1);
$("#datepicker_eind").datepicker("setDate", dateValue);

Help implementing past date validation

I need to implement something that checks if a given date is greater than today. If for example, I input a date of April 19, 2011 while today is April 15, 2011, there should be some validator/pop up error. How do I implement this?
I have my system date (today's date) working fine through php. I just don't know how to create a validation/error message when the user inputs a higher date than today.
It can be done with PHP (on server side) and with JavaScript (on client side, in browser).
Here is an example of how to do it on JavaScript:
var currentTime = new Date()
month = currentTime.getMonth(),
day = currentTime.getDate(),
year = currentTime.getFullYear(),
today = year + "-" + month + "-" + day;
var users_day = '2011-04-19';
if (users_day > today) {
alert ("Entered day is greater than today");
}
else {
alert ("Today is greater than entered day");
}
For example (in PHP)
date_default_timezone_set(date_default_timezone_get()); // not necessary here
$today = strtotime('2011-04-15');
$users_day = strtotime('2011-04-19');
if ($users_day > $today) {
echo "Error";
}
else {
echo "OK";
}
Example above outputs
Error
...because April 19, 2011 (user's input) is greater than April 15th, 2011 (today).

Categories