I have a string :
$Value = 03/25/2014 10:15 AM
I would like to convert this to a mysql timestamp. When I use date('Y-m-d H:i:s', $Value) it does not work. Can someone please help me convert this? Thank you.
date needs a UNIX timestamp:
$Date = date('Y-m-d H:i:s', strtotime($Value));
Related
I have this DateTime format.
2016-11-22 12:04 PM
I want to convert it to UTC datetime which can be inserted into MysQL.
Can somebody please tell how to do it with carbon?
Set your timezone and add this code something like this.Hope this will be helped you.
$timestamp = '2016-11-22 12:04 PM';
$date = Carbon::createFromFormat('Y-m-d H:i A', $timestamp, 'America/New_York');
$date->setTimezone('UTC');
I need to conver timestamp to 2016-07-12 format. This is what I tried.
$selectedDate=date('m/d/Y H:i:s', '1465430400000');
I got 08/23/48407 00:00:00 I need to conver it to 2016-07-12 format.
Please Note: Here the format m/d/Y H:i:s isn't the matter. I'm getting wrong date is the problem
Any suggetion would be appricieated.
It looks like your timestamp is 1000x what date() expects, so try first dividing it by 1000 (and then, of course, use the right date format):
$selectedDate = date('Y-m-d', 1465430400000/1000);
You can convert Date in Any format:
<?php $date1 = strtotime($old_date);
echo $date = date("y-M-d", $date1); ?>
Complete list of format options
I am using a array where they use unixtimestamp, like 1421241074.
Any idea how to convert it to date? I know that strtotime is date to unixtimestamp and that is exactly what I don't want.
I am trying something like this at the moment:
foreach ($response as $key => $value) { //this works
$timestamp = substr($value['timestamp'], 6, 13); //this works
$timestamp = ('m/d/Y H:i:s', $timestamp); // this supose to convert unixtimestamp to date. fail!
but this is not working, someone here with a idea?
You need the date() php function:
date('m/d/Y H:i:s', $timestamp);
In your code you forgot the date part of date()!
date('m/d/Y H:i:s', $timestamp);
Try to read about the timestamp function, in the documentation you should see about converting unix.
Maybe is a dumb question, but I can't find the proper function:
I have a string date like 04/05/2012
How I can pass to this format: 2012-04-05 20:18:11 to insert in mySQL?
Combination of date and strtotime ...
$my_date = date('Y-m-d H:i:s',strtotime('04/05/2012'));
$dateTime = new DateTime($your_time_string);
echo $dateTime->format("Y-m-d H:i:s");
Time can not be 'made' on its own. If you're however inserting the current date-time setting, then the following code will be used:
$dt = date( "Y-m-d H:i:s", time() );
You may use dleiftah's statement, but the time in that case will always be 00:00:00
I am having a strange problem, maybe you can help:
I'm trying to convert a date to GMT time, and this is what I'm doing:
$date = '2010-05-27 23:02:01';
$gmt_date = gmdate('Y-m-d H:i:s', $date );
but the yield of $gmt_date is this:
1970-01-01 00:33:31
What am I doing wrong?
gmdate expects the second parameter to be an integer (the number of seconds from the unix epoch)
Try this:
$date = '2010-05-27 23:02:01';
$gmt_date = gmdate('Y-m-d H:i:s', strtotime($date) );
You need to convert your $date into a timestamp. You can do this using the strtotime() function. Depending on timezones, you may want to set the php timezone or append a timezone to the $date string before calling the strtotime function.
$gmdate_str = gmdate('Y-m-d H:i:s', strtotime($date));