This question already has answers here:
Is there any jQuery plugin for Hijri calendars?
(3 answers)
Closed 6 years ago.
I am working on a project that has a form which requires the user to input a date using the Hijri (Arabic) calendar. I am only familiar with Javascript datepickers for the Gregorian calendar.
I searched a lot on the internet and the closest I got was JS code for the Persian calendar, which is in Arabic, but everything else is different. For example the names of the days, months etc. And the Persian calendar is based on the solar calendar.
Anyway, please advise on what I can do.
Thanks.
You have to use a library/class do that conversion job for you, one of the available options is what Ar-PHP library provides (it is free open source library published under LGPL license), please find below an example code:
date_default_timezone_set('UTC');
$time = time();
require('I18N/Arabic.php');
$obj = new I18N_Arabic('Date');
$fix = $obj->dateCorrection ($time);
echo $obj->date('l dS F Y h:i:s A', $time, $fix);
You can find a life example and check the output here
More information about how calculation itself done can be found here
The Arabic PHP Project may help you with PHP.
http://www.ar-php.org/features-php-arabic.html
Related
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to compare the date parts of two Zend_Date objects?
I've been trying to compare dates, but for some reason things don't seem to work as I want them to.
I'm trying to log to a database whenever someone logs into my site on a certain day.
I've used if (date("j F") == "25 July") followed by my code, but it doesn't seem to trigger.
I intend to get it to check for a lot of things, such as Friday 13, 17 March, etc (obviously I know I'll need to change the date() format for Friday 13).
The current check of 25 July is a copy from an echo of date(), so I know it's definitely not a typo. Can anyone tell me why this isn't working, and how to do it?
Cheers
The best method is to use a strtotime function. But I think it won't work until you specify year in the date.
Not sure about it though. But strtotime is a good option.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Convert one date format into another in PHP
I am currently pulling from my SQL database the event dates i.e in the table field date it will display (2011-12-08) however i wish to have it output December 8th, 2011 rather than 2011-12-08 when display through php on my website. Any ideas on how to go about this?
As people have said, for questions like this please search around first before asking since many places on the web and many other questions in stackoverflow already cover this. That said, my advice is to store the date in the database as a datetype because it will allow mysql to do its operations easier then convert the the human readable form upon displaying it using the php date function which would use format "F jS, Y" for what you want. Good luck and welcome to stackoverflow.
1) I have been working on fetching data from an excel sheet i can see on a cell written Oct-10 but when i select it i see 10/31/2000 on fx column right at top ,when i fetch data from the .xls sheet using http://phpexcel.codeplex.com library version number 1.7.3 ,it is returning float("40482") ,
can any body tell how to convert it to either 10/31/2000"/"Oct-10 all the cells other than this one are reading correctly so there is no error in code.
2) Also Please tell how can i get a better tutorial for this library as one provided on this site is not very helpful or i am using wrong library.
thanks in advance
See answer to this question Days since 1900
or read section 3.2 (and specifically 3.2.3) in the not very helpful "PHPExcel Function Reference Developer Documentation" which describes exactly how to convert between Excel dates and PHP dates (or PHP date/time objects).
The function you're after is:
$PHPdateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
or
$PHPdateObject = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
There are links to a number of tutorials in a variety of languages on the documents section of the PHPExcel website. And in addition to the documentation, there's plenty of code examples in the /Tests subdirectory of the distribution
Example of returning a PHP date/time object:
include 'PHPExcel.php';
$excelDateValue = 40482.0;
$dateObj = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
echo $dateObj->format('Y-m-d H:i:s');
displays
2010-10-31 00:00:00
How can I create a calendar in PHP?
Today should be in bold. How could it be coded?
You can try dhtml Calendar, or maybe Yahoo UI's Calendar.
PHP: date should give you everything you need.
Then, format everything in a table.
Firstly, start by capturing your requirements (should it handle month browsing, should it show a week at a time, etc.) - this should let you derive a functional spec of sorts, which should guide you when actually writing the component/page/application
If you mean: "how to show a date picker on your web page from PHP", the answer is to use some default JavaScript library for it. E.g. Dojo or jQuery.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I calculate relative time?
I want to format dates on my social web app much like Digg.com and other sites do. There, you see very friendly dates, such as:
just now
3 minutes ago
one hour ago
2 weeks ago
6 months ago
etc
Before I wrap my head around creating such a thing, does anyone know of any ready-to-go script for this where I simply insert a datestamp and a friendly date text is given based on how it related to the current time?
PS: I need this in PHP, but pseudo-code or any other language is fine too.
This is a duplicate of this question. It has a flurry of code samples on how to accomplish this, in addition to the code this very site uses. I glanced at it and there seems to be a PHP implementation posted there too.
In addition to all this, if are you using jQuery you can do this client-side with something like the timeago plugin. It has the advantage of updating the text as time passes so if you load a page and it says "posted 5 minutes ago" and look again 5 minutes later, it says "posted 10 minutes ago"
Thanks all for the answers, and sorry for the duplicate question. I did not find the duplicate when I was looking for it because I did not really know what search terms to use.
Anyways, I have my problem solved thanks to the PHP translation of the code used by stackoverflow. I made one tiny change in calculating the delta:
$delta = strtotime(gmdate("Y-m-d H:i:s", time())) - $time;
Since I am storing my dates in MySQL as timestamp in the GMT format, I have to use the same for calculating the CURRENT time. This makes for a timezone neutral comparison, which is exactly what is needed in my case.
You can also do this in SQL:
Best way to convert DateTime to "n Hours Ago" in SQL