Dates in Blue Prism Code Stages: parsing, formats and robot locale
Updated 25 September 2026 · Every C# sample here compiles with the compiler that ships with Blue Prism.
Date bugs follow a well-known pattern in Blue Prism. The process works on the developer's laptop, then fails in production with String was not recognized as a valid DateTime. Worse, it silently swaps day and month: 03/04 becomes 4 March instead of 3 April. The cause is almost always the same. The robot's Windows account has different regional settings from yours, and the code let the machine choose the date format.
This guide shows how to make date handling in a Code Stage independent of the machine it runs on.
Setup
Add System.Globalization to Namespace Imports in Code Options on the Initialise page. It's part of mscorlib, so no DLL reference is needed.
Blue Prism dates arrive as DateTime
A Blue Prism Date, DateTime or Time input reaches your code as a .NET DateTime. It's already a date, so there's nothing to parse. The problems start when the date arrives as Text: from a screen, an email, a PDF or an Excel cell read as text.
Parse text dates with an explicit format
Never use DateTime.Parse(text) on its own. It uses the current machine's culture. Say which formats you accept, and parse with the invariant culture:
string[] formats = { "dd/MM/yyyy", "d/M/yyyy", "dd-MM-yyyy", "yyyy-MM-dd" };
DateTime parsed;
Is_Valid = DateTime.TryParseExact((Date_Text ?? "").Trim(), formats,
CultureInfo.InvariantCulture, DateTimeStyles.None, out parsed);
Result_Date = Is_Valid ? parsed : DateTime.MinValue;
Inputs: Date Text (Text). Outputs: Is Valid (Flag), Result Date (Date).
TryParseExactreturnsfalseinstead of throwing, so a bad value goes to a Decision stage (a business exception) rather than a system exception.- The formats array lists every layout you expect.
d/M/yyyyalso accepts3/4/2026without leading zeros. 3/4/2026is read as 3 April here, because the formats say day first. If your source is American, putM/d/yyyyfirst instead. Decide this explicitly; don't let the robot's settings decide it for you.
Month names
Text like 05 Mar 2026 has a month name, and month names depend on language. Name the culture:
DateTime d = DateTime.ParseExact(Date_Text, "dd MMM yyyy", CultureInfo.GetCultureInfo("en-GB"));
Iso_Date = d.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
Long_Date = d.ToString("dddd, d MMMM yyyy", CultureInfo.GetCultureInfo("en-GB"));
For 05 Mar 2026 this gives Iso_Date = 2026-03-05 and Long_Date = Thursday, 5 March 2026.
Format dates for output with a fixed pattern
When you write a date into a form field, a file name or an API request, always pass the format and the culture to ToString:
Formatted = Input_Date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
Without CultureInfo.InvariantCulture, the / in the pattern is replaced with the machine's date separator. On some regional settings dd/MM/yyyy comes out as 05.03.2026 or 05-03-2026.
Excel serial dates
Excel stores dates as numbers of days, so a date cell read as a raw value can come back as something like 46086. Convert it with FromOADate:
Result_Date = DateTime.FromOADate(double.Parse(Excel_Value, CultureInfo.InvariantCulture));
46086 becomes 5 March 2026. Use this when a "date" from Excel looks like a five-digit number.
Add working days
A common SLA calculation: the date N working days after a start date, skipping weekends. With inputs Start Date (Date) and Days (Number):
DateTime d = Start_Date.Date;
int remaining = (int)Days;
while (remaining > 0)
{
d = d.AddDays(1);
if (d.DayOfWeek != DayOfWeek.Saturday && d.DayOfWeek != DayOfWeek.Sunday)
remaining--;
}
Due_Date = d;
For public holidays, pass them in as a collection and skip those dates as well.
Checklist
- Parse with
TryParseExactand an explicit list of formats, never plainParse. - Pass
CultureInfo.InvariantCulture, or a named culture for month names, every time you parse or format. - Decide day-first or month-first from the source of the data, not from any machine's settings.
- Treat an unparseable date as a business exception, not a crash.
Related
- Regex in a Code Stage, to pull the date out of free text first
- How to write a Code Stage
More Code Stage guides
- How to write a Code Stage in Blue Prism: inputs, outputs, namespaces and references
- Filter a Blue Prism collection without a loop (DataView and LINQ)
- Remove duplicate rows from a Blue Prism collection
- Parse JSON in a Blue Prism Code Stage (no third-party DLL)
- Blue Prism Code Stage compile errors and how to fix them
- Regex in a Blue Prism Code Stage: match, extract and validate
- Code Stage vs Loop stage: making Blue Prism collection work faster