Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PatrickL's avatar

Converting a a Float Representation of a Date to Carbon Object

One of the components of my application needs to convert a date (in float format), that it receives from another component, back into a Carbon object for processing and other stuff. But, I am uncertain how to go about converting it.

My app's first component returns a float (using Carbon's valueOf() method). The reason I chose this approach is to make it ideal to pass into javascript. Bur, other components of the application's backend also need to receive and process such dates.

So, how would I go about converting a date in float format, (i.e. float(1349479571124)) to a Carbon object, or, at the very least, a datetime string that I can parse into a Carbon object.

Thanks.

0 likes
2 replies
jlrdw's avatar

how would I go about converting a date in float format

Do not use date in float format. Float will mess you up. Just do a search about the evil of floats.

PatrickL's avatar

@jlrdw Oh. Okay then. So, I guess I’ll stick to a strong representation.

Please or to participate in this conversation.