askvity

What is the Date Format for Azure API?

Published in Azure API 2 mins read

The date format used in Azure APIs is generally YYYY-MM-DD.

While YYYY-MM-DD is the common base format, Azure APIs often employ variations depending on the specific API and property involved. These variations often include time components and timezone information. Let's break down the possibilities:

  • Basic Date Format: YYYY-MM-DD (e.g., 2024-01-01). This is the most straightforward date format and is often used for properties that only require a date and not a specific time.

  • Date and Time Format: YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.fffZ (e.g., 2024-01-01T12:00:00Z or 2024-01-01T12:00:00.123Z). Here:

    • T separates the date and time.
    • HH is the hour (24-hour format).
    • mm is the minute.
    • ss is the second.
    • fff represents milliseconds (optional).
    • Z indicates UTC timezone (Zulu time).
  • Date and Time with Timezone Offset: YYYY-MM-DDTHH:mm:ss+HH:mm or YYYY-MM-DDTHH:mm:ss-HH:mm (e.g., 2024-01-01T12:00:00+05:30). This format includes the timezone offset from UTC. +HH:mm indicates the timezone is ahead of UTC, and -HH:mm indicates it's behind.

Key Considerations:

  • API Documentation is Crucial: Always consult the specific Azure API's documentation for the definitive date format required for each property. The documentation will explicitly state the expected format.
  • UTC is Often Preferred: Many Azure services prefer or require UTC dates and times to ensure consistency across different regions.
  • Serialization/Deserialization Libraries: When working with Azure APIs in code, use appropriate date/time serialization and deserialization libraries to handle date format conversions correctly. Libraries like Newtonsoft.Json (in .NET) or Jackson (in Java) provide powerful tools for handling date formats.

Example Scenarios:

  • Creating a Virtual Machine: The creationDate property might use YYYY-MM-DDTHH:mm:ssZ.
  • Querying Activity Logs: Filters based on time range may require YYYY-MM-DDTHH:mm:ss.fffZ.
  • Setting a Resource Expiry: The expiryDate might accept YYYY-MM-DD.

In summary, while YYYY-MM-DD is a fundamental part of the Azure API date format, always refer to the specific API documentation to determine the exact format, including whether time components and timezone information are necessary.

Related Articles