Working with PowerShell for over a decade, I’ve often needed to combine text with dates and times—especially for file naming, logging, and automation tasks. If you’ve ever wanted to add today’s date to a report filename or include a timestamp in your logs, you’re in the right place.
In this tutorial, I’ll show you several ways to concatenate strings and DateTime values in PowerShell. I’ll use simple, real-world examples—like generating a filename with today’s date for a New York-based report or creating a log entry for a user named “Jessica”—so you can see exactly how this works in practice.
Let’s dive right in!
PowerShell Basics: Strings and DateTime
Before we jump into concatenation, let’s quickly review how PowerShell handles strings and DateTime objects.
- Strings are sequences of characters, like
"Hello, World!"or"Report_". - DateTime is a special object type representing dates and times, like
2025-06-05 14:30:00.
When you combine these, you often want the date in a specific format (like MM-dd-yyyy).
Check out Concatenate Strings and Floats in PowerShell
Method 1: Using the Plus (+) Operator
The simplest way to concatenate strings and DateTime in PowerShell is by using the + operator. However, you need to convert the DateTime object to a string first—otherwise, you’ll get an error.
Example: Filename with Today’s Date
Suppose I want to create a report file for “Jessica” with today’s date:
$user = "Jessica"
$date = Get-Date
$filename = $user + "_Report_" + $date.ToString("MM-dd-yyyy") + ".csv"
Write-Host $filenameOutput:
Jessica_Report_06-05-2025.csvHere is the exact output in the screenshot below:

Key Points:
- Always use
.ToString()with your desired format for DateTime. - This method is straightforward and works well for simple cases.
Read Concatenate String with Space in PowerShell
Method 2: Using String Interpolation ($())
PowerShell supports string interpolation, which lets you embed variables (and even expressions) directly inside double-quoted strings.
Example: Log Entry with Timestamp
Let’s say you want to log when “Michael” ran a script:
$user = "Michael"
$timestamp = Get-Date
$logEntry = "$user started the process at $($timestamp.ToString('yyyy-MM-dd HH:mm:ss'))"
Write-Host $logEntryOutput:
Michael started the process at 2025-06-05 16:10:43You can see the exact output in the screenshot below:

Why I Like This:
- Clean and readable.
- You can include formatting directly inside the string.
Read Split a String by Semicolon in PowerShell
Method 3: Using the -f Format Operator
The -f operator is powerful for building formatted strings, especially when you want to control the output layout.
Example: Backup File with Date and Time
Suppose you’re backing up a database in Chicago and want the file to include both date and time:
$city = "Chicago"
$date = Get-Date
$backupFile = "{0}_Backup_{1:yyyyMMdd_HHmmss}.bak" -f $city, $date
Write-Host $backupFileOutput:
Chicago_Backup_20250605_161043.bakYou can also see the exact output in the screenshot below:

Advantages:
- Great for complex formatting.
- Easy to read and maintain, especially with multiple variables.
Read Split String by Space in PowerShell
Method 4: Using StringBuilder for Large Loops
If you need to concatenate many strings—say, building a large log or report in a loop—using [System.Text.StringBuilder] is much more efficient.
Example: Building a Multi-Line Log
$sb = New-Object System.Text.StringBuilder
foreach ($user in @("Jessica", "Michael", "David")) {
$entry = "{0} logged in at {1:MM/dd/yyyy HH:mm}" -f $user, (Get-Date)
$null = $sb.AppendLine($entry)
}
Write-Host $sb.ToString()Output:
Jessica logged in at 06/05/2025 16:12
Michael logged in at 06/05/2025 16:12
David logged in at 06/05/2025 16:12When to Use This:
- Best for performance when concatenating inside large loops.
- Avoids the overhead of repeated string operations.
Read Concatenate String and Variable in PowerShell
Formatting DateTime for USA Standards
In the USA, the most common date formats are:
| Format | Example Output | PowerShell Format String |
|---|---|---|
| MM/dd/yyyy | 06/05/2025 | ToString("MM/dd/yyyy") |
| yyyy-MM-dd | 2025-06-05 | ToString("yyyy-MM-dd") |
| MM-dd-yyyy HH | 06-05-2025 16:15 | ToString("MM-dd-yyyy HH:mm") |
Tip:
Always specify your date format to avoid confusion, especially if your scripts run on different systems or are shared with others.
Check out Concatenate String with NewLine in PowerShell
Concatenate String and Datetime Without Time using PowerShell
Now, let me show you how to concatenate a string and a DateTime value in PowerShell, with two practical methods and examples.
1. Using the Plus (+) Operator
The best way to concatenate a string and a DateTime value in PowerShell is by using the + operator. However, you must convert the DateTime object to a string using .ToString() or -Format.
Example:
Suppose you want to generate a filename for a daily report:
$reportName = "DailyReport_"
$date = Get-Date
$filename = $reportName + $date.ToString("yyyy-MM-dd") + ".csv"
Write-Host $filenameOutput:
DailyReport_2025-06-05.csvHere, .ToString("yyyy-MM-dd") formats the date in a USA-friendly way.
2. Using String Interpolation
String interpolation lets you embed variables and expressions directly in a double-quoted string. You can format the DateTime inline.
Example:
Let’s create a log entry with a timestamp:
$user = "Jessica"
$timestamp = Get-Date
$logEntry = "$user logged in at $($timestamp.ToString('MM/dd/yyyy HH:mm'))"
Write-Host $logEntryOutput:
Jessica logged in at 06/05/2025 16:30This method is ideal for building user messages or logs in PowerShell.
Read Concatenate Strings Inside Loops in PowerShell
Common Mistakes and How to Avoid Them
Here are some common mistakes that you might make, and you can avoid them:
- Forgetting
.ToString()on DateTime: PowerShell won’t automatically convert DateTime to string in concatenation. Always use.ToString(). - Using Single Quotes for Interpolation: Single quotes (
' ') do not expand variables. Use double quotes (" "). - Locale Issues: Date formats can change based on the system locale. Explicitly set your format string to ensure consistency.
Conclusion
In this tutorial, I explained how to concatenate a string and a datetime in PowerShell using different methods. We saw different methods with examples. Do let me know in the comments below if you still have any questions.
You may also like:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.