Discord Guide

Date to Unix Timestamp — Complete Guide

June 29, 2026 · 10 min read

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 epochJanuary 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.

Pro Tip:Always verify your conversion by running it in reverse. Take the unix timestamp you generated and paste it into the Unix Timestamp Converter at /unix-timestamp-converter. If the date displayed matches what you started with, the conversion is correct. This takes 10 seconds and catches timezone errors before they reach production.

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 secondsJavaScript 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.

Pro Tip:When converting dates in JavaScript, use ISO 8601 strings with the Z suffix explicitly — new Date('2026-06-29T13:00:00Z') — rather than new Date('2026-06-29 13:00:00'). The space-separated format is not part of the ISO standard and different browsers parse it differently, producing inconsistent results across environments.

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


Frequently Asked Questions

Use Math.floor(new Date('2026-06-29T13:00:00Z').getTime() / 1000). The getTime() method returns milliseconds so you must divide by 1000 to get seconds. Always use an ISO 8601 date string ending in Z to ensure UTC parsing. Discord requires seconds (10 digits) not milliseconds (13 digits).
Use the datetime module: int(datetime(2026, 6, 29, 13, 0, 0, tzinfo=timezone.utc).timestamp()). Always pass timezone.utc explicitly to avoid daylight saving time errors from your system's local timezone setting.
You are passing milliseconds instead of seconds. JavaScript Date.getTime() returns a 13-digit millisecond value. Divide it by 1000 to get the 10-digit seconds value. Discord requires seconds (10 digits) not milliseconds (13 digits).
Yes. A unix timestamp counts seconds elapsed since midnight UTC on January 1 1970. It has no timezone built in — it is always measured from UTC. When you display it you convert to whatever local timezone you want, but the underlying integer value is always UTC-based.
Use SELECT UNIX_TIMESTAMP('2026-06-29 13:00:00'). This returns the 10-digit seconds value directly. Make sure your MySQL server timezone is set to UTC to avoid offset errors in the output.
Use the formula =(A1 - 25569) * 86400 where A1 contains your date. Excel counts days from January 1 1900, so you subtract the epoch offset of 25,569 days before multiplying by 86,400 seconds per day. Format the result cell as a Number with zero decimal places.
Always use ISO 8601 format — 2026-06-29T13:00:00Z. The Z suffix means UTC. This format is parsed consistently across all programming languages, databases, and operating systems. Avoid locale-specific formats like 06/29/2026 which are interpreted differently depending on system settings.
Generate the 10-digit seconds value using any method above, then wrap it in Discord's timestamp format: . Replace the number with your value and replace F with your preferred format code. The [Discord Timestamp Generator](/) does this automatically — just pick a date and copy the generated code.

Ready to generate Discord timestamps?

Open the Generator

Did You Miss These?

Discord Guide

Generate a Discord Timestamp

Free tool — all 7 formats, live Discord preview, auto timezone detection.

Open Generator →
Discord Guide8 min read

Jun 29, 2026

Discord Countdown Timer — Complete Guide

How to create a live Discord countdown timer using timestamps and bots. Step-by-step guide with format codes and common mistakes.

Read Article →
Discord Guide8 min read

Jun 29, 2026

Unix Timestamp to Date — Complete Guide

How to convert a Unix timestamp to a human readable date in JavaScript, Python, PHP, Java, MySQL and more. Code examples and common mistakes covered.

Read Article →
Discord Guide9 min read

Jun 29, 2026

Unix Timestamp in Python, JavaScript, and PHP

Complete code examples for Unix timestamps in Python, JavaScript, PHP, Java, MySQL and more. Get current timestamp, convert dates, handle milliseconds.

Read Article →
Discord Guide8 min read

Jun 28, 2026

What Is a Unix Timestamp?

Learn what a Unix timestamp is, how it works, why it starts in 1970, and how it connects to Discord timestamps.

Read Article →
Discord Guide8 min read

Jun 28, 2026

Epoch vs Unix Time — Are They the Same?

Epoch and Unix time are used interchangeably but have a strict technical difference. Learn what sets them apart and how Discord uses them.

Read Article →
Discord Guide6 min read

Jun 27, 2026

How to Make Time Zone Messages in Discord

How to send Discord messages that automatically show the right local time for every reader worldwide.

Read Article →
Discord Guide7 min read

Jun 26, 2026

How to Set a Time on a Discord Message

Learn how to use Discord timestamps to set a time on any message that auto-converts for every time zone.

Read Article →
Discord Guide8 min read

Jun 8, 2026

What Is a Discord Timestamp?

Learn what a Discord timestamp is, how discord time codes work, all 7 formats explained with examples.

Read Article →