Ive used date() before but I do not remember how to store it in mysql. VARCHAR, TEXT, TIMESTAMP?

Dani AI

Generated

Short answer for : use a native date/time column, not VARCHAR/TEXT. As noted, pick the right type for the data you need: DATE for date-only values, DATETIME for a recorded date+time (no automatic timezone conversion), and TIMESTAMP when you want MySQL to store times in UTC and convert to the session time zone or use automatic CURRENT_TIMESTAMP behavior.

Key differences to watch for: TIMESTAMP is timezone-aware (MySQL converts between session time_zone and UTC) and has a more limited range (about 1970–2038). DATETIME stores the literal value and supports a much wider range and fractional seconds in modern MySQL releases. For authoritative behavior and version details see the MySQL manual: Date and Time Types.

From PHP, format values to the SQL standard before inserting and use prepared statements. Common patterns:

$now = date('Y-m-d H:i:s'); // DATETIME/TIMESTAMP format
// bind $now to a prepared INSERT for a created_at column

See the PHP date() docs for format options: PHP date().

Practical tips and cautions: index date columns you query by. Standardize on UTC for storage (either use TIMESTAMP or store UTC DATETIME) and convert to local time only for display to avoid subtle bugs. Use BIGINT only if you need millisecond epoch values; otherwise Unix INT timestamps will hit the 2038 limit. Avoid VARCHAR/TEXT for dates — they block indexing and date functions. ’s linked tutorial is a reasonable starter; use the official docs above for exact semantics and version-specific behavior.

Recommended Answers

All 2 Replies

Click here....to get an idea about date datatype in mysql and how to work on it....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.