API testing and development involve many details, including the current date within GET requests. This can be a crucial aspect of simulating real-world scenarios.
Try Apidog for free today by clicking the button below!
This article explores two effective methods for incorporating the current date as a GET request value within Postman, a popular API client. We will delve into utilizing pre-request scripts and environment variables, equipping you with the necessary tools to construct dynamic and adaptable GET requests.
What is Postman?

Postman simplifies the API development process for programmers. It provides a variety of features that allow them to design, test, and document APIs all in one place. This collection of tools makes Postman the preferred choice for developers working on any project involving APIs.
Postman Pre-request Scripts
In Postman, pre-request scripts are snippets of JavaScript code that execute before you send an API request. They act like a prep station, allowing you to perform actions and manipulations on your request just before it goes out.
Dynamic Request Modification
Pre-request scripts allow you to modify your API requests on the fly using JavaScript. This enables you to incorporate dynamic elements like the current date, random test data, or access tokens based on specific scenarios.
Configurability
These scripts can be written at various levels within Postman, offering flexibility:
- Request Level: Scripts written here are specific to that particular request.
- Collection Level: Scripts at this level run before every request within a collection.
- Folder Level: These scripts apply to all child requests within a designated folder.
Enhanced Reusability
Scripts can be designed to leverage data from environments or previous requests, promoting reusability and reducing repetitive code.
Customization of Request Components
You can modify various aspects of your request using pre-request scripts, including headers, body content, and query parameters.
Debugging and Logging
These scripts allow you to log information to the Postman console, aiding in debugging your API interactions and troubleshooting any issues.
Step-by-step Guide on How to Pass Current Date as GET Request Value
Step 1 - Create a Postman Account
Create a new Postman account (only if you do not have one) and start downloading the Postman application onto your device. The application offers more features than its web version.

Step 2 - Create a New API Request on Postman

Once you have installed Postman, create a new request by clicking the New
button in the top left corner of the Postman window. Select HTTP Request
to create a new request, as shown in the image above.
Step 3 - Enter API Method and Details
Next, you need to include the details of the API request you wish to create. It must include components such as the URL, HTTP methods, and additional parameters the API will require.
Step 4 - Open the Pre-Request Script
Section

On your completed API, search for the Pre-request script
section, as shown in the image above.
Step 5 - Insert Necessary Code For Including Date
Under the Pre-request Script
tab, add the following lines of code so that you can include the current date.
var moment = require('moment');
pm.environment.set('currentdate', moment().format(("YYYY-MM-DD HH:MM:SS")));
For this particular example, the timestamp will be stored in the currentdate
variable using the pm.environment.set
method.
Step 6 - Include the currentdate
Variable as a Request Variable

Add the currentdate
variable to the query parameter section of your GET request so that every time you send a request, you can observe the current date.

Apidog - Personalize APIs
If you're looking for a powerful API development platform, consider Apidog as an alternative to Postman. Apidog streamlines the process by handling many of the intricate details for you. Dive into the following sections to explore how Apidog helps you visualize these API specifics!

Including Current Date in Request Headers in Apidog
To include the current timestamp in the API request header, follow these steps below!

The following code snippet can be used to incorporate the current date into an API request header. Simply copy and paste these lines into a custom script within the Pre-request Scripts section (previously labeled Pre Processors) as illustrated in the image.
var timestamp = new Date().getTime();
pm.environment.set("timestamp", timestamp);

Once you have initialized the timestamp variable, make sure to add the variable as a query parameter. See the image above for reference.
Viewing Date and More in Apidog API Request

Apidog goes beyond basic timestamps. It provides in-depth API details, including cookies and raw request formats. This comprehensive view empowers you to pinpoint issues and refine your APIs for seamless deployment. Additionally, consider API load testing to further assess your API's robustness.

In conclusion, this article explored two effective methods for incorporating the current date as a GET request value within Postman: pre-request scripts and environment variables. Pre-request scripts offer flexibility for dynamic manipulation, while environment variables provide reusability across requests. By leveraging these techniques, you can construct adaptable and dynamic GET requests that simulate real-world scenarios and enhance the effectiveness of your API testing and development.
Furthermore, the ability to include dynamic elements like the current date underscores the power of Postman as an API development tool. This empowers you to create more robust and realistic test cases, ultimately leading to the deployment of APIs that are well-equipped to handle a wider range of conditions.