Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge Date & Time

Tags:

$combinedDT = date('Y-m-d H:i:s', strtotime('$date $time')); 

Date Format 2013-10-14

time format 23:40:19

i'm getting zeros when trying to store into a datetime datatype

like image 354
CodeGuru Avatar asked Oct 15 '13 07:10

CodeGuru


People also ask

What day is the ETH Merge?

The Ethereum merge, a long-awaited shift in the technological underpinnings of the world's second-most valuable cryptocurrency, is scheduled to be complete sometime between Sept. 10 and Sept. 20.

What is the merge Ethereum?

The Merge represents the Ethereum network's shift to proof-of-stake (PoS), its new system (also called a “consensus mechanism”) for authenticating crypto transactions. The new system will replace proof-of-work (PoW), the more power-hungry mechanism pioneered by Bitcoin.

What will ETH 2.0 do?

Ethereum 2.0 will involve sharding to drastically increase network bandwidth and reduce gas costs, making it cheaper to send Ethereum, tokens, and interact with smart contracts. There will be fundamental economic changes too, Ethereum 2.0 will allow supports to staking nodes and earn Ethereum as passive income.

What happens to my ETH after merge?

All funds will transfer over after The Merge, and ether will still appear as ETH in users' wallets. However, Binance will temporarily pause ETH and ERC-20 token deposits and withdrawals until The Merge is complete.


2 Answers

You're currently doing strtotime('$date $time'). Variables wrapped in single-quotes aren't interpolated. If you use single-quotes, PHP will treat it as a literal string, and strototime() will try to convert the string $date $time into a timestamp.

It'll fail and that would explain why you're getting incorrect results.

You need to use double quotes instead:

$combinedDT = date('Y-m-d H:i:s', strtotime("$date $time"));                                             ^           ^ 
like image 90
Amal Murali Avatar answered Oct 27 '22 22:10

Amal Murali


And for those coming here working with DateTime objects:

$date = new DateTime('2017-03-14'); $time = new DateTime('13:37:42');  // Solution 1, merge objects to new object: $merge = new DateTime($date->format('Y-m-d') .' ' .$time->format('H:i:s')); echo $merge->format('Y-m-d H:i:s'); // Outputs '2017-03-14 13:37:42'  // Solution 2, update date object with time object: $date->setTime($time->format('H'), $time->format('i'), $time->format('s')); echo $date->format('Y-m-d H:i:s'); // Outputs '2017-03-14 13:37:42' 
like image 22
Wilbo Baggins Avatar answered Oct 27 '22 21:10

Wilbo Baggins