The first time I needed to convert date to unix timestamp for a Discord bot, I spent twenty minutes confused about why my timestamps were displaying dates in the year 275760. Turns out I was passing milliseconds when the system expected seconds. One division by 1000 fixed everything.
This guide covers every method to convert date to unix timestamp — from manual formula to code examples in every major programming language — so you get the right 10-digit value every time.
If you just need a quick conversion right now, the Unix Timestamp Converter handles it instantly. For Discord-ready timestamp codes, use the Discord Timestamp Generator.
What Is a Date to Unix Timestamp Conversion?
A unix timestamp is the number of seconds that have elapsed since the unix epoch — January 1 1970 at midnight UTC. Converting a human-readable date like "June 29 2026 at 1:00 PM" into a unix timestamp means calculating exactly how many seconds have passed between January 1 1970 and that moment.
The result is a plain integer value — a single number with no timezone, no formatting, no punctuation. This machine-readable format is what programming languages, databases, and APIs use internally to store and compare dates consistently across every system in the world.
Why Convert a Date to Unix Timestamp?
Timezone agnostic storage — A unix timestamp is identical everywhere on Earth. Store it once and convert to any local timezone on display. No need to store timezone data alongside your dates.
Simple calculations — Finding duration between two dates means one subtraction. No calendar logic needed. Want to know how many seconds are between two events? Subtract one unix timestamp from the other.
Sorting and filtering — Numbers sort naturally. Databases index and filter unix timestamps faster than formatted date strings.
Cross-platform consistency — Every programming language and operating system understands unix timestamps. No locale differences, no month day year order confusion, no format mismatches.
Scheduling — Discord bots, cron jobs, and scheduling systems all use unix timestamps internally to know when to trigger an action.
Logging and version control — Systems like Git attach a unix timestamp to every commit. Log files use epoch time for precise event sequencing and debugging.
How to Convert Date to Unix Timestamp — Manual Formula
If you want to understand what is happening under the hood, here is the manual calculation.
The current unix epoch started on January 1 1970. As of that date, approximately 70,569 days have passed to reach mid-2026. The formula is: Unix Timestamp = (Days since January 1 1970) × 86400 + (Hours × 3600) + (Minutes × 60) + Seconds
In Excel or LibreOffice, you can use this formula where A1 contains your date:
=(A1 - 25569) * 86400
Note: Excel's epoch offset starts from January 1 1900, which is 25,569 days before the unix epoch. The result must be formatted as a Number with zero decimal places to get a clean integer value.
How to Convert Date to Unix Timestamp in Code
JavaScript
JavaScript Date.getTime() returns milliseconds — always divide by 1000 to get seconds.
// Current timestamp in seconds
Math.floor(new Date().getTime() / 1000)
// Specific date in seconds
Math.floor(new Date('2026-06-29T13:00:00').getTime() / 1000)
Discord requires seconds (10 digits) not milliseconds (13 digits). If you skip the division you will get a 13-digit value that breaks any Discord timestamp or standard unix time comparison.
Python
Use the native datetime module. The datetime approach is timezone-aware which avoids daylight saving time errors.
from datetime import datetime, timezone
# Current timestamp
int(datetime.now(timezone.utc).timestamp())
# Specific date
dt = datetime(2026, 6, 29, 13, 0, 0, tzinfo=timezone.utc)
int(dt.timestamp())
PHP
Use the built-in strtotime function. Always pass a UTC date string to avoid timezone confusion.
// Current timestamp
time()
// Specific date
strtotime('2026-06-29 13:00:00 UTC')
Java
System.currentTimeMillis() returns milliseconds — divide by 1000 for seconds.
// Current timestamp in seconds
long timestamp = System.currentTimeMillis() / 1000;
// Specific date
import java.time.Instant;
long specific = Instant.parse("2026-06-29T13:00:00Z").getEpochSecond();
MySQL
-- Current timestamp
SELECT UNIX_TIMESTAMP();
-- Specific date string
SELECT UNIX_TIMESTAMP('2026-06-29 13:00:00');
PostgreSQL
-- Current timestamp
SELECT EXTRACT(EPOCH FROM now());
-- Specific date
SELECT EXTRACT(EPOCH FROM TIMESTAMP '2026-06-29 13:00:00');
-- Difference in seconds from baseline
SELECT DATEDIFF(SECOND, '1970-01-01', '2026-06-29 13:00:00');
SQL Server
SELECT DATEDIFF(SECOND, '1970-01-01', '2026-06-29 13:00:00');
Bash / Unix Linux Shell
# Current timestamp
date +%s
# Specific date string
date -d '2026-06-29 13:00:00' +%s
Timezone Handling — The Most Important Step
Timezone handling is where most date to unix timestamp conversions go wrong.
A unix timestamp is always measured from midnight UTC on January 1 1970. This means when you convert a date, you must tell the system whether your input date is in UTC or a local timezone — otherwise it applies your system's timezone offset and produces the wrong value.
Example of the problem: If your system is set to GMT+5 and you convert "June 29 2026 13:00:00" without specifying UTC, you get a value that is 5 hours off from what you intended.
Best practice: Always work in UTC internally. Store unix timestamps in UTC. Convert to local timezone only at the display layer.
In Python, use timezone.utc explicitly. In JavaScript, use ISO 8601 format strings ending in Z (e.g. 2026-06-29T13:00:00Z). In PHP strtotime, append UTC to your date string. In MySQL, use CONVERT_TZ if your server timezone differs from UTC.
Seconds vs Milliseconds — The One Mistake That Breaks Everything
This single issue causes more date to unix timestamp bugs than everything else combined.
10 digits — seconds — Standard unix time. What Discord, most databases, PHP time(), Python .timestamp(), and Unix systems return. Example: 1782721148
13 digits — milliseconds — What JavaScript Date.getTime() returns by default. Example: 1782721148000
The fix is always the same: divide by 1000.
// Wrong — milliseconds
new Date('2026-06-29').getTime() // 1782720000000
// Correct — seconds
Math.floor(new Date('2026-06-29').getTime() / 1000) // 1782720000
If you paste a 13-digit value into a Discord timestamp format code you will get a date in the year 275,760. If you use the Unix Timestamp Converter it handles both formats and tells you which one you have.
Common Mistakes When Converting Date to Unix Timestamp
Wrong timezone assumption — Forgetting to specify UTC when the system defaults to local timezone. Always be explicit. A single GMT+5 offset adds 18,000 seconds to your value silently.
Using milliseconds instead of seconds — JavaScript returns milliseconds by default. Discord requires seconds (10 digits) not milliseconds (13 digits). Always divide JavaScript timestamps by 1000.
Daylight saving time errors — Converting a date in a region that observes daylight saving time without accounting for the offset produces values that are one hour off for half the year. Use UTC throughout to avoid this entirely.
Wrong date string format — Different languages parse date strings differently. 06/29/2026 is June 29 in the US but fails or produces wrong results in many European locale settings. Always use ISO 8601 format — 2026-06-29T13:00:00Z — to guarantee consistent parsing across all systems.
Excel epoch offset confusion — Excel counts days from January 1 1900, not January 1 1970. The epoch offset difference is 25,569 days. Forgetting to subtract this produces a value that is about 70 years too large.
Negative timestamps for dates before 1970 — Dates before January 1 1970 produce negative unix timestamps. Many older APIs and databases do not handle negative values correctly. Always test historical date handling if your application needs it.
How to Verify Your Conversion
Always do a reverse check after converting. Take the unix timestamp you produced and convert it back to a human-readable date using the Unix Timestamp Converter. If the output matches your original input date and time in UTC, the conversion is correct.
For Discord specifically, paste your 10-digit value into the Discord Timestamp Generator and preview all 7 format options before using it in a message. This confirms the date, time, and timezone display exactly as intended.
Related Guides
- Unix Timestamp to Date — Complete Guide
- What Is a Unix Timestamp?
- Unix Timestamp Converter
- Discord Timestamp Generator
Frequently Asked Questions
Ready to generate Discord timestamps?
Open the Generator