Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a string in PHP that is equivalent to yyyyMMddHHmmssffff

I am trying to integrate with some VB code that generates a string using

DateTime.Now.ToString("yyyyMMddHHmmssffff")

The closest I can get to this in PHP has been

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

date('YmdHis')

But this lacks the milliseconds,

I have tried playing with microtime e.g.

date('YmdHis',time()).substr(str_replace(".","",microtime(true)),10,17)

But sometimes this results in a shorter string

>Solution :

date function always returns zero for microseconds. Use DateTime -> format and chop the last two digits off so that 4 fractional digits are left.

substr((new DateTime()) -> format('YmdHisu'), 0, 18);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading