diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index ac99345fa6dc7db9a5ca0cc6b047c6a5e55819e2..2e3eab6599d2dbf37cb501e30c2d2fea4bfb0121 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -61,16 +61,22 @@ EOF
 	print $f <<EOF;
   </PropertyGroup>
 EOF
+
+	# We have to use this flag on 32 bit targets because the 32bit perls
+	# are built with it and sometimes crash if we don't.
+	my $use_32bit_time_t = 
+	  $self->{platform} eq 'Win32' ? '_USE_32BIT_TIME_T;' : '';
+
 	$self->WriteItemDefinitionGroup(
 		$f, 'Debug',
-		{   defs    => '_DEBUG;DEBUG=1;',
+		{   defs    => "_DEBUG;DEBUG=1;$use_32bit_time_t",
 			opt     => 'Disabled',
 			strpool => 'false',
 			runtime => 'MultiThreadedDebugDLL' });
 	$self->WriteItemDefinitionGroup(
 		$f,
 		'Release',
-		{   defs    => '',
+		{   defs    => "$use_32bit_time_t",
 			opt     => 'Full',
 			strpool => 'true',
 			runtime => 'MultiThreadedDLL' });
diff --git a/src/tools/msvc/VCBuildProject.pm b/src/tools/msvc/VCBuildProject.pm
index 1022329dce2f70b938290b08eceb7776c2fb58cb..624682601b3180b41b850d8a0ef3cd188399722d 100644
--- a/src/tools/msvc/VCBuildProject.pm
+++ b/src/tools/msvc/VCBuildProject.pm
@@ -32,9 +32,16 @@ sub WriteHeader
  <Platforms><Platform Name="$self->{platform}"/></Platforms>
  <Configurations>
 EOF
+
+	# We have to use this flag on 32 bit targets because the 32bit perls
+	# are built with it and sometimes crash if we don't.
+	my $use_32bit_time_t = 
+	  $self->{platform} eq 'Win32' ? '_USE_32BIT_TIME_T;' : '';
+
+
 	$self->WriteConfiguration(
 		$f, 'Debug',
-		{   defs     => '_DEBUG;DEBUG=1;',
+		{   defs     => "_DEBUG;DEBUG=1;$use_32bit_time_t",
 			wholeopt => 0,
 			opt      => 0,
 			strpool  => 'false',
@@ -42,7 +49,7 @@ EOF
 	$self->WriteConfiguration(
 		$f,
 		'Release',
-		{   defs     => '',
+		{   defs     => "$use_32bit_time_t",
 			wholeopt => 0,
 			opt      => 3,
 			strpool  => 'true',