3 months ago

Working with dates and DB

Posted 3 months ago by cyjobes

I would like to get opinions of the method I have used in the past for dates. In addition I would like thoughts I how I might do this better.

Usually in my DB table I will have to columns for a date. For example, if it is a start date the columns might be start_date (08/13/2019) and start_date_ts (a strtotime timestamp).

The first is for having a readable/displayable date, while the other is used for calculating date using comparisons of greater than, less than or equal on the the timestamped version to get the results I need. This has been my go-to for a long time and works well.

Ive looked at Carbon, but their documentation is not all that great for finding some examples that are more likely to be used than how they display it. At least that is my experience with it so far.

A lot f what I do deals with a start and end dates. Using the timestamps I can do quick calculations to find records with dates that may land on or between a certain date.

Im a lone, self-taught developer, with no one to bounce things off of. Any advice on best practices and how to best use dates would be very much appreciated.

Please sign in or create an account to participate in this conversation.