This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Joomla 2.5 displays wrong datetime
i am trying to display current date and time in my component as below:
<?php
$date =& JFactory::getDate();
echo 'Current date and time is: ' . $date->toFormat() . "\n";
?>
i've set the timezone to Asia/Dhaka in my machine, joomla server configuration and even in php.ini but still the returned value is 6 hours late. Please suggest me what is the problem?
Try using JFactory::getDate('now') to use the server's current time. If that doesn't help you can add the second option to set your timezone offset.
Since I'm East coast US, I would use to force EST:
JFactory::getDate('now' , -5)
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
I have a html form that sends a date, I set this to a variable within the php and it is outputted in this format: 01/01/2000. Edit I can't change the format in which I receive the date-it's a pre-set html file.
I need to use this variable for a SQL query on a database that dates format is like this 2000-01-01. So how can I change this format and assign it to a new variable?
So
$dateOne = $_REQUEST["date_1"]; #Outputs 01/01/2000
I would like 2000-01-01.
I've read a lot on here about doing this but can only manage to get 1970-01-01 by using date('Y-m-d', strtotime($dateOne)); which I think is being reset due to strtotime?
Very new to this so sorry if I have overlooked something very simple.
This is my quick solution to this problem.
$date = DateTime::createFromFormat('m/d/Y',$_REQUEST["date_1"])->format('Y-m-d');
This question already has an answer here:
PHP date() shows tomorrow's date
(1 answer)
Closed 8 years ago.
I have a basic php script
<?php
$today = date("Y-m-d");
echo $today;
?>
Which should output 2014-11-14. However, I am getting output of 2014-11-15 even though my system tray displays 2014-11-14.
I changed the system date back one day (13th) and I got the output I wanted (14th)... Earlier today I had to do a system restore and ran Malwarebytes because I picked up a virus. Could this be the cause of this?
Does anyone know where else I can check my systems time other than the system tray?
date() function uses unix timestamps which always is set to +0:00
So use:
date_default_timezone_set('Europe/Zurich');
When you set your default timezone it will automaticly calculate the offset!
the date() function is returning UTC time and not the time on your local computer
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
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:
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