Remove Time from Timestamp: How & When
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator converts a timestamp that includes a time of day into just the date part, or into the number of days since a chosen starting date. You enter the timestamp value and its unit (seconds, milliseconds, or a date-time text), and you get back the date alone, plus the day count if you want it. The result is shown in a clear, readable format that you can copy into a spreadsheet, database, or report.
Formula
The core idea is that a timestamp is just a number of seconds (or milliseconds) since a fixed reference point, usually January 1, 1970 (the Unix epoch). To remove the time, you divide by the number of seconds in a day (86,400) and take the floor (round down) to get the whole day number. Then you can convert that day number back to a date.
In symbols:
- D = floor( T / 86400 )
- Where T is the timestamp in seconds, and D is the day number (days since epoch).
- If your timestamp is in milliseconds, first divide by 1000 to get seconds.
- If your timestamp is a text like “2024-01-15 14:30:00�, you first convert it to a date-time object (in your programming language or spreadsheet), then extract the date part.
The calculator above assumes you enter a numeric timestamp in seconds. For text timestamps, the same logic applies, but the conversion is handled by the software you are using.
Worked Example
Using the default values: timestamp = 2024-01-15 14:30:00 (which we treat as the numeric seconds value, but for clarity let’s convert it manually).
- First, convert the timestamp to a date-time object. In many systems, you can parse it directly.
- Extract the date part: 2024-01-15.
- If you need the day number, calculate the number of days since the epoch. For 2024-01-15, that is 19741 days (since 1970-01-01).
- The calculator’s formula for the date output uses the floor of the timestamp in seconds divided by 86400. For a timestamp of 2024-01-15 00:00:00 (in seconds), that would be 19741 exactly.
So the result is: Date only: 2024-01-15, and Days since start: 19741 (if start is 1970-01-01).
When to Remove Time from a Timestamp
You often need to strip the time component when you are grouping data by day, comparing dates without time, or storing a date in a database where time is irrelevant. Common scenarios include:
- Creating daily reports from event logs that have full timestamps.
- Joining two tables on a date key, where one table has date-only values.
- Calculating age or tenure in whole days.
- Removing timezone effects when you only care about the calendar date.
For example, if you have a list of user sign-ups with exact times, you might want to see how many signed up per day. Removing the time makes that grouping straightforward.
How to Do It in Common Tools
The method depends on where your data lives:
- Excel: Use =INT(A1) if the cell contains a date-time serial number. Format the cell as a date. Or use =TEXT(A1,”YYYY-MM-DD”) to get a text string.
- Google Sheets: Same as Excel, use =INT(A1) and format as date, or =TEXT(A1,”YYYY-MM-DD”).
- Python (pandas): Use df[‘date’] = df[‘timestamp’].dt.date or .dt.normalize().
- SQL: Use CAST(timestamp_column AS DATE) in most databases, or DATE(timestamp_column) in MySQL, or ::date in PostgreSQL.
- JavaScript: Use new Date(timestamp).toISOString().split(‘T’)[0] for a date string.
Each method effectively truncates the time part, either by rounding down to the nearest day or by extracting the date component.
Common Mistakes and Misconceptions
One frequent error is confusing seconds with milliseconds. Many APIs return timestamps in milliseconds (e.g., JavaScript’s Date.now()). If you divide a millisecond timestamp by 86400, you get a huge number, and the date is wrong. Always check the unit first.
Another misconception is that removing the time means rounding to the nearest day. That is not correct; you want to truncate (floor) the timestamp to the start of that day. For example, 2024-01-15 23:59:59 should become 2024-01-15, not 2024-01-16.
Also, beware of timezone issues. A timestamp is an absolute point in time. When you convert it to a date, the date can differ depending on the timezone you are in. For instance, 2024-01-15 23:00:00 UTC is 2024-01-16 in UTC+2. Always decide which timezone you want the date to represent.
Comparing with Other Approaches
There are several ways to handle date-only values, each with trade-offs:
- Storing as text (YYYY-MM-DD): Simple and readable, but sorting and arithmetic are not natural.
- Storing as a date type: Best for databases, but not all systems have a pure date type.
- Storing as an integer day count: Efficient for calculations, but less human-readable.
- Storing as a timestamp with time at midnight: Common in legacy systems, but can cause off-by-one errors if timezones are not handled.
For most applications, using a dedicated date type or truncating the timestamp at the application level is the cleanest.
Limitations of the Formula
The formula works perfectly for timestamps that are Unix-like (seconds or milliseconds since epoch). However, it does not handle:
- Timestamps before 1970 (negative values) – the floor function still works, but you must be careful with the date conversion.
- Leap seconds – Unix time ignores them, so they are not an issue in practice.
- Text timestamps – you need to parse them first, which may involve timezone parsing.
Also, the day count output assumes you want the difference in whole days. If you need to include the start day, add 1 to the difference.
Frequently Asked Questions
Q: How do I remove the time from a timestamp in Excel?
A: If the cell contains a date-time value, use =INT(A1) and format the result as a date. For example, =INT(45291.5) gives 45291, which formatted as a date shows 2024-01-15.
Q: What is the difference between truncating and rounding a timestamp?
A: Truncating (floor) always goes to the beginning of the day, so 23:59 becomes 00:00. Rounding would go to the nearest day, so 23:59 would become the next day. For removing time, you want truncation.
Q: Why do I get the wrong date when I remove the time from a millisecond timestamp?
A: You likely forgot to divide by 1000 first. Millisecond timestamps are about 1000 times larger than second timestamps. For example, 1705314600000 ms is 1705314600 seconds, which is 2024-01-15.
Q: Does removing the time affect timezone handling?
A: Yes. The date you get depends on the timezone you convert to. For example, a timestamp of 1705314600 (2024-01-15 14:30:00 UTC) becomes 2024-01-15 in UTC, but 2024-01-15 in UTC+2 as well, but 2024-01-15 in UTC-5. Always specify the timezone.
Q: Can I use this calculator for timestamps before 1970?
A: Yes, the formula works with negative numbers, but the date conversion may not be straightforward in all systems. The calculator assumes a standard epoch, so negative values will produce dates before 1970.
Q: How do I get the date in a specific format like DD/MM/YYYY?
A: After truncating, format the result using your software’s date formatting options. In Excel, use a custom format like DD/MM/YYYY. In Python, use strftime(‘%d/%m/%Y’).
Related
Formula used
in t | Timestamp | - | 2024-01-15 14:30:00 | 0 in s | Start date | - | 1970-01-01 | 0 out date | Date only | YYYY-MM-DD | floor(t / 86400) | 0 out days | Days since start | days | floor(t / 86400) - floor(s / 86400) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.