What format of a timestamp is this? - php

I have to make some changes on an wordpress plugin.
The plugin gives back this timestamp format: 1364495828.1500
What's the name of this format and how can I change it to DD/MM/YYYY - HH:MM???
I am using PHP
Thanks!

This is a UNIX timestamp to a resolution of 100 microseconds.
Try this to get it into a DATETIME format in your SQL statement.
FROM_UNIXTIME(1364495828.1500)
You can also give a second parameter to the function containing a DATE_FORMAT string, and get the date string you want. For example, this gets you a timestamp string like 16/06/2013 14:25
FROM_UNIXTIME(1364495828.1500, '%d/%m/%Y - %H:%i')
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
But, if you're working in WordPress, you may prefer to do this in PHP. If you use PHP code like this you'll use the WordPress date format and time format settings chosen by the user, and get the the kind of result your user expects.
$timestring = date_i18n( get_option( 'date_format' ), '1364495828.1500' ) .
' ' .
date_i18n( get_option( 'time_format' ), '1364495828.1500' );
These are chosen on the general settings page in WordPress's administrative interface.

It's just the result of:
$ts = microtime(true); // 1368731778.7964 as I write this
a standard UNIX timestamp with microseconds included.

try this(didn't test it):
date('d-m-Y - H:i',strtotime('1364495828.1500'));
this code tries to find out time it is en set it to a data and the date function format it for you

Related

strtotime display one date before in php

I've a date in the format dd/mm/YYYY. Eg: 25/06/2015.
I want convert it to timestamp. I've added the following code to implement this;
$timestamp = strtotime( str_replace( '/', '-', '25/06/2015' ) );
It creates timestamp, but when I convert that timestamp I can see that it is one day before. When I execute the above code, I got the timestamp value "1435183200". When I convert this I got the previous date "24/06/2015".
If anybody knows the solution to fix this, please help.
I think you have the default timezone configured in PHP. Try switching your timezone. Use:
date_default_timezone_set('your_timezone_here');
For a list of supported timezones, go to http://php.net/manual/en/timezones.php

How to display date in kurdish using php

In php the date() function displays the date. But I have to display the date in kurdish language.. any one help me.
for example ..have to display the date like this
٢\١٢\٢٠١٤
As your Q is tagged WordPress, you can use date_i18n() to retrieve the date in localized format, based on timestamp:
echo date_i18n( get_option( 'date_format' ), time() )
You need to encode the given string to whatever charset you are using.
This is not bound to kurdish but to any language which cannot be displayed by your systems defauld charset.

CodeIgniter/JQuery/MySQL DateTime

Within my CodeIgniter app, I'm using a Jquery calendar pop-up that also captures time as set by the user, so the end result looks like: MM-DD-YYYY HH:MM, and I'm storing this in MySQL into a DateTime field that is: YYYY-MM-DD HH:MM:SS. What is the best (most efficient) way to push the date/time into MySQL so that it saves properly, and to pull is back out of MySQL and render it on the screen in the reverse format? Thanks!
Most efficient way is to use the ISO 8601 standard to pass date values between the client and server. Since the client and server talks in strings you'd be parsing the date to a string before sending it either way. The best format I prefer is the combined date and time in UTC:
2011-06-14T13:57Z
There are no spaces and it's clean. Then you'll have to parse it on the server side (should be relatively easy using PHP) and parse it on the client side.
For displaying purposes, I prefer to extend JavaScript's Date.prototype to include a format function that imitates PHP's date format.
Once you include the linked script from above you could do this on the server side -
var today = new Date();
alert(today.format('m-d-Y H:i')); //displays "06-14-2011 11:18"
Good luck!
I think you should use the strptime() function to parse the date received from the jQuery calendar your using and using mktime():
// Parse the time based on your jQuery calendar's format
$parts = strptime($calendar_value, '%m-%d-%Y %H:%M');
if ( ! empty($parts) )
{
// Create a Unix timestamp
$timestamp = mktime($parts['tm_hour'], $parts['tm_min'], 0, $parts['tm_mon'] + 1, $parts['tm_mday'], $parts['tm_year'] + 1900);
// Create a string representation of the Unix timestamp
$date = date(DATE_ISO8601, $timestamp);
}
You'll want to use $date to insert in your database. There is a function called "strtotime" which will attempts to parse dates that are in human-readable format but I doubt it's able to determine if the month or day comes first, especially if they're both lower than 12 which is why I chose to use "strptime" instead.
When you pull the data from MySQL, you can then simply use the date() and strtotime() function to populate the calendar:
echo date('m-d-Y h:i', strtotime($mysql_date));

php generate date/ time in the same format appears mysql datatime

I would like to know if there is a function in php to generate data/time format like in mysql : 0000-00-00 00:00:00 .
I know you can generate data/time in the sql query with CURDATE() but I would like to know if it's possible to generate it with php in the same format mysql datatime format .
Sure is! Give this a go date('Y-m-d H:i:s')
At the moment PHP only supports RFC 2822 and ISO 8601 conform dates as well as Unix epoch timestamp. Check more here.
The reason for that is probably that they include timezone offset, and the "mysql form" - its a localized compbound format - doesnt, which would often lead to a mess in when using with application servers.
But you can define your own formats as you like, all the components are available via the datetime functions. Just have a look here and here
Example:
$mysql_date = date('Y-m-d H:i:s', $unix_timestamp);
But be aware of the Y2k38 bug if you are not on a 64 bit system, you may want to use the datetime class
This should convert the standard formats:
$format = 'DATETIME';
$format = str_replace(
array('DATETIME', 'DATE', 'TIME', 'YEAR'),
array('DATE TIME', 'Y-m-d', 'H:i:s', 'Y'),
$format);
echo date($format, time());

choosing time and AM or PM

i have an option value for time in main form and another option for am or pm...now what confuses me is how am i going to code it when if example i choese 1 and then pm...how am i goin to call it on the database?i also have to filter the sales reports by time and by pm.. hope someone can help me..thanks
You can set AM/PM through capital A or lowercase a depending on your preference of capital AM/PM or lowercase am/pm. As far as your question on how to interact with the database, your time inserted should be unedited, IE you don't want to apply the styling from the date function and insert that into your database as a string because that will prevent you from changing it in the future. Instead create a DATETIME or TIMESTAMP column in your table, and put the date in that, then when you select from the table you can apply styling to fit your needs.
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
http://www.php.net/manual/en/function.date.php
From Database to Display
The PHP Function [date()][1] can be used to convert a Unix Timestamp into a Human-Readable form.
<?php
// $time is assumed as a Timestamp from DB or other
echo date( 'g:i:sa, l jS F Y' , $time );
?>
Will Return
3:43pm, Wednesday 25th August 2010
Alternately, you could use the [strftime()][2] which performs a similar role, but has different placeholders (it also lacks the placeholder for "st","nd","th" after the day number). The benefit of this function is that you could include plain text within the format, as all placeholders are prefixed with "%" - so "hello" would not be treated as a placeholder.
<?php
// $time is assumed as a Timestamp from DB or other
echo strftime( '%l:%M:$S%P, %A %e %B %Y' , $time );
?>
Will Return
3:43pm, Wednesday 25 August 2010
Translating User-Entered Data into a Format for the Database
Most databases I have worked with have been pretty intelligent about how they handle timestamps. All you should need to do is, if there are more than one field being used (ie one for hour, one for minutes, one for am/pm), join them together into a single string, and just make sure that the resulting string is of a format able to be parsed by PHP.
The function strtotime() can turn a Human-readable time into a Unix Timestamp, which your database should be able to handle without any problems.
<?php
// $input is the string (joined or solo) containing the Human-readable timestamp
$input = "2010/08/25 3:43pm";
if( ( $out = strtotime( $input ) )===false ){
echo 'Timestamp "'.$input.'" Unrecognisable';
}else{
echo $out;
}
?>
Will Return
1282743780
If the string being parsed is not recognisable according to the PHP Date Time Formats, then it will return false.

Categories