⚙️ Settings
WITH recent_orders AS (
SELECT
customer_id,
order_id,
order_date,
total_amount
FROM orders
WHERE order_date >= DATEADD(day, -30, GETDATE())
)
SELECT
customer_id,
COUNT(order_id) AS order_count,
SUM(total_amount) AS total_spent
FROM recent_orders
GROUP BY customer_id
ORDER BY total_spent DESC;
WITH RECURSIVE employee_hierarchy AS (
-- Anchor: top-level rows (no manager)
SELECT
employee_id,
manager_id,
employee_name,
1 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Recursive: join children to their parent's result
SELECT
e.employee_id,
e.manager_id,
e.employee_name,
eh.level + 1
FROM employees e
INNER JOIN employee_hierarchy eh
ON e.manager_id = eh.employee_id
)
SELECT *
FROM employee_hierarchy
ORDER BY level, employee_name;
-- Note: SQL Server / Oracle: drop the RECURSIVE keyword (just WITH employee_hierarchy AS (...))
SELECT
o.order_id,
c.customer_name,
o.order_date,
p.product_name,
oi.quantity
FROM orders o
INNER JOIN customers c
ON o.customer_id = c.customer_id
LEFT JOIN order_items oi
ON o.order_id = oi.order_id
LEFT JOIN products p
ON oi.product_id = p.product_id
WHERE o.order_date >= '2026-01-01'
ORDER BY o.order_date DESC;
SELECT
DATE_TRUNC('month', order_date) AS order_month, -- PostgreSQL
-- FORMAT(order_date, 'yyyy-MM') AS order_month, -- SQL Server
-- DATE_FORMAT(order_date, '%Y-%m') AS order_month, -- MySQL
COUNT(*) AS order_count,
SUM(total_amount) AS revenue
FROM orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY order_month;
SELECT
customer_id,
order_id,
order_date,
total_amount,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY order_date DESC
) AS order_rank,
SUM(total_amount) OVER (
PARTITION BY customer_id
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_total
FROM orders;
CREATE PROCEDURE GetCustomerOrders
@CustomerId INT,
@StartDate DATE = NULL,
@EndDate DATE = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT
order_id,
order_date,
total_amount
FROM orders
WHERE customer_id = @CustomerId
AND (@StartDate IS NULL OR order_date >= @StartDate)
AND (@EndDate IS NULL OR order_date <= @EndDate)
ORDER BY order_date DESC;
END;
-- Call it: EXEC GetCustomerOrders @CustomerId = 101, @StartDate = '2026-01-01';
MERGE INTO customers AS target
USING staging_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET
target.customer_name = source.customer_name,
target.email = source.email,
target.updated_at = GETDATE()
WHEN NOT MATCHED THEN
INSERT (customer_id, customer_name, email, created_at)
VALUES (source.customer_id, source.customer_name, source.email, GETDATE());
#FACC15
rgb(250, 204, 21)
rgb(98%, 80%, 8%)
hsl(46, 96%, 53%)
hsv(46, 92%, 98%)
cmyk(0%, 18%, 92%, 2%)
Unit Converter — Data Size & Time Converter (Bytes to TB, Seconds to Years)
This Unit Converter converts data storage sizes (bytes through petabytes) and time durations (milliseconds through years) into every related unit at once. It's built for developers and analysts who need a quick bytes to gigabytes converter while sizing a database or estimating a file transfer, or who need to convert a duration like seconds into a more readable unit like hours or days. Enter a value, pick a category and starting unit, and see it converted everywhere at once.
⚡ Key Takeaways
- Converts data size (bytes to petabytes) and time (milliseconds to years) instantly.
- Uses binary (1,024-based) units for data size, matching how operating systems report file sizes.
- All unit values update live as you type, with no separate convert step.
- A quick way to sanity-check storage estimates or API duration values.
What, Who, When & Why
| What it's for | Converts data sizes (bytes to petabytes) and time durations (milliseconds to years) into every related unit at once. |
|---|---|
| Who it's for | Developers and analysts estimating storage needs or converting durations from logs and APIs. |
| When to use it | When sizing a database, estimating a file transfer, or converting a duration into a more readable unit. |
| Why it's needed | Manually calculating binary (1,024-based) conversions between data units is error-prone, and duration units in logs are often in an inconvenient scale. |
| Best way to use it | Confirm whether a spec sheet uses binary (1,024) or decimal (1,000) units, since this tool uses binary and results can differ from decimal sources. |
How to Use the Unit Converter
- Choose a category: Data Size or Time.
- Enter the value you want to convert.
- Select the unit your value is currently in (the "from" unit).
- The result updates instantly, showing your value converted into every other unit in that category.
Conversion Formula
Data size conversions use binary (base-1024) multiples, which is the standard used by operating systems for file sizes:
| Unit | Bytes |
|---|---|
| 1 KB | 1,024 B |
| 1 MB | 1,024 KB = 1,048,576 B |
| 1 GB | 1,024 MB |
| 1 TB | 1,024 GB |
| 1 PB | 1,024 TB |
Time conversions use standard fixed-length units: 60 seconds per minute, 60 minutes per hour, 24 hours per day, 7 days per week, and 365 days per year.
Example
Entering 1 GB and converting shows:
B = 1073741824 KB = 1048576 MB = 1024 GB = 1 TB = 0.000977
This makes it easy to answer questions like "how many megabytes are in a gigabyte" (1,024) or "how many gigabytes is 500,000 KB" without doing the arithmetic by hand. The same live-updating approach works for time — entering 90 minutes instantly shows the equivalent in seconds, hours, days, and beyond.
Key Features
- Converts data size across six units at once: bytes, KB, MB, GB, TB, PB.
- Converts time across seven units at once: milliseconds, seconds, minutes, hours, days, weeks, years.
- All conversions update live as you type — no separate "convert" click needed.
- One-click copy of the full conversion table.
Practical Use Cases
- Estimating storage needs: convert an expected data volume in MB into GB or TB for capacity planning.
- Understanding file sizes: quickly check how many megabytes a multi-gigabyte file actually is.
- Converting durations: turn a duration given in seconds (common in logs and APIs) into a more readable unit like hours or days.
- Sanity-checking calculations: verify a data transfer time estimate by converting between size and known transfer rates.
- Comparing storage plans: convert between GB and TB when comparing cloud storage or hosting plan sizes.
Tips for Best Results
- Double-check whether a spec sheet or vendor is using binary (1,024-based) or decimal (1,000-based) units, since this tool uses binary and results may differ slightly from decimal-based sources.
- Use the time category to quickly sanity-check API rate limits or timeout values expressed in seconds or milliseconds.
- Copy the full conversion table when documenting size or duration specs for a technical document.
Related Terminology
Data size units are commonly measured in binary multiples of 1,024 (as this tool does, matching how operating systems report file sizes), though some contexts use decimal multiples of 1,000 (as some hard drive manufacturers do) — this is a well-known source of confusion when a "1TB" drive shows less than 1TB of usable space in your operating system.
Important Considerations
Because this tool uses binary (1,024-based) multiples for data size, values may differ slightly from tools that use decimal (1,000-based) multiples — both are valid conventions used in different contexts, so it's worth confirming which convention a given system or spec uses when precision matters, especially for storage capacity planning or purchasing decisions.
Related Tools
Working with timestamps instead of durations? The Epoch Converter converts Unix timestamps to human-readable dates. Need to generate a sequence of dates instead? Try the Date Range Generator.
Frequently Asked Questions
How many megabytes are in a gigabyte?
1 gigabyte equals 1,024 megabytes, using the binary convention this tool follows (the same one operating systems use to report file sizes).
Does this use 1,000 or 1,024 for data size conversions?
This tool uses 1,024 (binary) for each step between units — B to KB, KB to MB, and so on — matching how most operating systems calculate file and storage sizes.
Can I convert time durations as well as data sizes?
Yes, switch the category to Time to convert between milliseconds, seconds, minutes, hours, days, weeks, and years.
Does the converter update automatically as I type?
Yes, all unit values update live as soon as you change the input value, category, or starting unit.
Why might my drive show less storage than advertised?
Manufacturers often use decimal (1,000-based) units for advertised capacity, while operating systems report usable space using binary (1,024-based) units — this mismatch is why a "1TB" drive typically shows a slightly smaller number in your file explorer.
Tools for analysts, developers & QA engineers
33 free, browser-based utilities — text and list tools, SQL helpers, converters, and small productivity apps. Everything runs locally; nothing you type or paste is ever uploaded.
For Analysts
Clean lists, build SQL fragments, and reshape data without opening a spreadsheet.
For Developers
Format SQL, convert data formats, and handle everyday text and encoding tasks.
For QA Engineers
Generate test data, compare text output, and sanitize queries before sharing them.