diff --git a/columninfo.c b/columninfo.c
index 7089fee..0d4583e 100644
--- a/columninfo.c
+++ b/columninfo.c
@@ -105,7 +105,7 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
 			/* Subtract the header length */
 			switch (new_adtid)
 			{
-				case PG_TYPE_DATETIME:
+				case PG_TYPE_TIMESTAMP_W_TMZONE:
 				case PG_TYPE_TIMESTAMP_NO_TMZONE:
 				case PG_TYPE_TIME:
 				case PG_TYPE_TIME_WITH_TMZONE:
diff --git a/convert.c b/convert.c
index ca01a57..5834e03 100644
--- a/convert.c
+++ b/convert.c
@@ -52,11 +52,14 @@
 CSTR	NAN_STRING = "NaN";
 CSTR	INFINITY_STRING = "Infinity";
 CSTR	MINFINITY_STRING = "-Infinity";
+CSTR	MINVALID_STRING = "-Invalid";
 
-#ifdef	__CYGWIN__
+#if defined(WIN32) || defined(__CYGWIN__)
 #define TIMEZONE_GLOBAL _timezone
-#elif	defined(WIN32) || defined(HAVE_INT_TIMEZONE)
+#define DAYLIGHT_GLOBAL _daylight
+#elif	defined(HAVE_INT_TIMEZONE)
 #define TIMEZONE_GLOBAL timezone
+#define DAYLOGHT_GLOBAL daylight
 #endif
 
 /*
@@ -218,54 +221,155 @@ static unsigned ODBCINT64 ATOI64U(const char *val)
 static void parse_to_numeric_struct(const char *wv, SQL_NUMERIC_STRUCT *ns, BOOL *overflow);
 
 /*
- *	TIMESTAMP <-----> SIMPLE_TIME
+ *		conversion support routines
+ *	timestamp string expression <-----> SIMPLE_TIME
+ *
  *		precision support since 7.2.
- *		time zone support is unavailable(the stuff is unreliable)
+ *		time zone support since 9.3.0500)
+ */
+
+static BOOL	use_local_time_zone = TRUE; 
+static BOOL	use_time_zone_expression = TRUE;
+#define	TIME_ZONE_TYPE(pgtype) ((pgtype) == PG_TYPE_TIMESTAMP_W_TMZONE || (pgtype) == PG_TYPE_ABSTIME)
+
+/*
+ *	Handle time zone expression zh[:zm[:zs]]
+ */
+static BOOL
+get_zone_hhmmss(const char *zonestr, char *zonehh, char *zonemm, char *zoness)
+{
+	int	hh, mm, ss;
+	int	scnt = sscanf(zonestr, "%d:%d:%d", &hh, &mm, &ss);
+	switch (scnt)
+	{
+		case 3:
+			*zonehh = (char) hh;
+			*zonemm = (char) mm;
+			*zoness = (char) ss;
+			break;
+		case 2:
+			*zonehh = (char) hh;
+			*zonemm = (char) mm;
+			break;
+		case 1:
+			*zonehh = (char) hh;
+			break;
+		default:
+			return FALSE;
+			break;
+	}
+	return TRUE;
+}
+
+/*
+ *	TIMESTAMP string expression -----> SIMPLE_TIME
  */
+#define	SECS_ONEDAY	(24 * 60 * 60)
+#define	SECS_ONEHOUR	(60 * 60)
+#define	SECS_ONEMIN	60
+
 static BOOL
-timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone)
+timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL considerZone)
 {
-	char		rest[64], bc[16],
-			   *ptr;
-	int			scnt,
-				i;
+	char		rest[64], bc[16], *ptr;
+	int			scnt, i;
 #ifdef	TIMEZONE_GLOBAL
 	long		timediff;
 #endif
-	BOOL		withZone = *bZone;
+	char		withZone;
+	time_t		t;
+	struct tm	tm, *tm2;
 
-	*bZone = FALSE;
-	*zone = 0;
+	withZone = 0;
 	st->fr = 0;
 	st->infinity = 0;
+	st->invalid = 0;
+	st->withZone = 0;
+	st->hh = st->mm = st->ss = 0;
+	st->zonehh = st->zonemm = st->zoness = 0;
 	rest[0] = '\0';
 	bc[0] = '\0';
-	if ((scnt = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d%31s %15s", &st->y, &st->m, &st->d, &st->hh, &st->mm, &st->ss, rest, bc)) < 6)
+	scnt = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d%31s %15s", &st->y, &st->m, &st->d, &st->hh, &st->mm, &st->ss, rest, bc);
+	if (scnt < 3 || scnt == 4 || scnt == 5) /* incomplete date/time expression */
+	{
+		if (strnicmp(str, INFINITY_STRING, 8) == 0)
+		{
+			st->infinity = 1;
+			st->m = 12;
+			st->d = 31;
+			st->y = 9999;
+			st->hh = 23;
+			st->mm = 59;
+			st->ss = 59;
+
+			return TRUE;
+		}
+		if (strnicmp(str, MINFINITY_STRING, 9) == 0)
+		{
+			st->infinity = -1;
+			st->m = 1;
+			st->d = 1;
+			// st->y = -4713;
+			st->y = -9999;
+			st->hh = 0;
+			st->mm = 0;
+			st->ss = 0;
+
+			return TRUE;
+		}
+		/*
+		 * The timestamp is invalid so set something conspicuous,
+		 * like the epoch
+		 */
+		t = 0;
+#ifdef	HAVE_LOCALTIME_R
+		tm2 = localtime_r(&t, &tm);
+#else
+		tm2 = localtime(&t);
+#endif /* HAVE_LOCALTIME_R */
+		st->m = tm2->tm_mon + 1;
+		st->d = tm2->tm_mday;
+		st->y = tm2->tm_year + 1900;
+		st->hh = tm2->tm_hour;
+		st->mm = tm2->tm_min;
+		st->ss = tm2->tm_sec;
+		if (strnicmp(str, MINVALID_STRING, 9) == 0)
+		{
+			st->invalid = 1;
+			st->m = 1;
+			st->d = 1;
+			// st->y = -4713;
+			st->y = -9999;
+			st->hh = 0;
+			st->mm = 0;
+			st->ss = 0;
+
+			return TRUE;
+		}
 		return FALSE;
+	}
 	else if (scnt == 6)
 		return TRUE;
 	switch (rest[0])
 	{
 		case '+':
-			*bZone = TRUE;
-			*zone = atoi(&rest[1]);
+			if (considerZone && get_zone_hhmmss(rest + 1, &st->zonehh, &st->zonemm, &st->zoness))
+				withZone = 1;
 			break;
 		case '-':
-			*bZone = TRUE;
-			*zone = -atoi(&rest[1]);
+			if (considerZone && get_zone_hhmmss(rest + 1, &st->zonehh, &st->zonemm, &st->zoness))
+				withZone = -1;
 			break;
 		case '.':
 			if ((ptr = strchr(rest, '+')) != NULL)
 			{
-				*bZone = TRUE;
-				*zone = atoi(&ptr[1]);
-				*ptr = '\0';
+				if (considerZone && get_zone_hhmmss(ptr + 1, &st->zonehh, &st->zonemm, &st->zoness))
+					withZone = 1;
 			}
 			else if ((ptr = strchr(rest, '-')) != NULL)
 			{
-				*bZone = TRUE;
-				*zone = -atoi(&ptr[1]);
-				*ptr = '\0';
+				if (considerZone && get_zone_hhmmss(ptr + 1, &st->zonehh, &st->zonemm, &st->zoness))
+					withZone = -1;
 			}
 			for (i = 1; i < 10; i++)
 			{
@@ -288,65 +392,88 @@ timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone)
 	{
 		st->y *= -1;
 	}
-	if (!withZone || !*bZone || st->y < 1970)
+	st->withZone = withZone;
+	if (!considerZone || !withZone || st->y < 1970)
+	{
 		return TRUE;
+	}
 #ifdef	TIMEZONE_GLOBAL
-	if (!tzname[0] || !tzname[0][0])
+	timediff = TIMEZONE_GLOBAL + withZone * (st->zonehh * SECS_ONEHOUR + st->zonemm * SECS_ONEMIN + st->zoness);
+	if (!DAYLIGHT_GLOBAL && timediff == 0) 	/* the same timezone */
 	{
-		*bZone = FALSE;
 		return TRUE;
 	}
-	timediff = TIMEZONE_GLOBAL + (*zone) * 3600;
-	if (!daylight && timediff == 0)		/* the same timezone */
+
+	tm.tm_year = st->y - 1900;
+	tm.tm_mon = st->m - 1;
+	tm.tm_mday = st->d;
+	tm.tm_hour = 0;
+	tm.tm_min = 0;
+	tm.tm_sec = 0;
+	tm.tm_isdst = -1;
+	t = mktime(&tm);
+	if (t < 0)
+	{
+		st->withZone = 0;
 		return TRUE;
-	else
+	}
+	t -= TIMEZONE_GLOBAL;
+	if (t % SECS_ONEDAY != 0)
 	{
-		struct tm	tm,
-				   *tm2;
-		time_t		time0;
-
-		*bZone = FALSE;
-		tm.tm_year = st->y - 1900;
-		tm.tm_mon = st->m - 1;
-		tm.tm_mday = st->d;
-		tm.tm_hour = st->hh;
-		tm.tm_min = st->mm;
-		tm.tm_sec = st->ss;
-		tm.tm_isdst = -1;
-		time0 = mktime(&tm);
-		if (time0 < 0)
-			return TRUE;
-		if (tm.tm_isdst > 0)
-			timediff -= 3600;
-		if (timediff == 0)		/* the same time zone */
-			return TRUE;
-		time0 -= timediff;
+		t = SECS_ONEDAY * (int) (t / SECS_ONEDAY);
+		if (TIMEZONE_GLOBAL < 0)
+			t += SECS_ONEDAY;
+		else
+			t -= SECS_ONEDAY;
+	}
+	t += (st->withZone * (SECS_ONEHOUR * (st->hh - st->zonehh)  + SECS_ONEMIN * (st->mm - st->zonemm) + st->ss - st->zoness));
 #ifdef	HAVE_LOCALTIME_R
-		if (time0 >= 0 && (tm2 = localtime_r(&time0, &tm)) != NULL)
+	if (t >= 0 && (tm2 = localtime_r(&t, &tm)) != NULL)
 #else
-		if (time0 >= 0 && (tm2 = localtime(&time0)) != NULL)
+	if (t >= 0 && (tm2 = localtime(&t)) != NULL)
 #endif /* HAVE_LOCALTIME_R */
+	{
+		st->y = tm2->tm_year + 1900;
+		st->m = tm2->tm_mon + 1;
+		st->d = tm2->tm_mday;
+		st->hh = tm2->tm_hour;
+		st->mm = tm2->tm_min;
+		st->ss = tm2->tm_sec;
+		if (TIMEZONE_GLOBAL < 0)
 		{
-			st->y = tm2->tm_year + 1900;
-			st->m = tm2->tm_mon + 1;
-			st->d = tm2->tm_mday;
-			st->hh = tm2->tm_hour;
-			st->mm = tm2->tm_min;
-			st->ss = tm2->tm_sec;
-			*bZone = TRUE;
+			st->withZone = 1;
+			st->zonehh = (signed char) (-TIMEZONE_GLOBAL / SECS_ONEHOUR);
+			st->zonemm = (signed char) ((-TIMEZONE_GLOBAL % SECS_ONEHOUR) / SECS_ONEMIN);
+			st->zoness = (signed char) (-TIMEZONE_GLOBAL % SECS_ONEMIN);
+			if (tm2->tm_isdst)
+				st->zonehh++;
+		}
+		else
+		{
+			st->withZone = -1;
+			st->zonehh = (signed char) (TIMEZONE_GLOBAL / SECS_ONEHOUR);
+			st->zonemm = (signed char) ((TIMEZONE_GLOBAL % SECS_ONEHOUR) / SECS_ONEMIN);
+			st->zoness = (signed char) (TIMEZONE_GLOBAL % SECS_ONEMIN);
+			if (tm2->tm_isdst)
+				st->zonehh--;
 		}
 	}
 #endif /* TIMEZONE_GLOBAL */
+
 	return TRUE;
 }
 
+/*
+ *	TIMESTAMP string expression <----- SIMPLE_TIME
+ */
 static BOOL
-stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision)
+stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL useZone, int precision)
 {
 	char		precstr[16],
 				zonestr[16];
 	int			i;
 
+mylog("!!! %s useZone=%d precision=%d\n", __FUNCTION__, useZone, precision);
 	precstr[0] = '\0';
 	if (st->infinity > 0)
 	{
@@ -358,12 +485,22 @@ stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision)
 		strcpy(str, MINFINITY_STRING);
 		return TRUE;
 	}
+	else if (st->invalid != 0)
+	{
+		strcpy(str, MINVALID_STRING);
+		return TRUE;
+	}
 	if (precision > 0 && st->fr)
 	{
+		int	precmax;
+
 		sprintf(precstr, ".%09d", st->fr);
 		if (precision < 9)
 			precstr[precision + 1] = '\0';
-		for (i = precision; i > 0; i--)
+		precmax = strlen(precstr);
+		if (precision < precmax)
+			precmax = precision;
+		for (i = precmax - 1; i > 0; i--)
 		{
 			if (precstr[i] != '0')
 				break;
@@ -373,33 +510,76 @@ stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision)
 			precstr[i] = '\0';
 	}
 	zonestr[0] = '\0';
-#ifdef	TIMEZONE_GLOBAL
-	if (bZone && tzname[0] && tzname[0][0] && st->y >= 1970)
+	if (useZone)
 	{
-		long		zoneint;
-		struct tm	tm;
-		time_t		time0;
-
-		zoneint = TIMEZONE_GLOBAL;
-		if (daylight && st->y >= 1900)
+		if (st->withZone > 0)
 		{
-			tm.tm_year = st->y - 1900;
-			tm.tm_mon = st->m - 1;
-			tm.tm_mday = st->d;
-			tm.tm_hour = st->hh;
-			tm.tm_min = st->mm;
-			tm.tm_sec = st->ss;
-			tm.tm_isdst = -1;
-			time0 = mktime(&tm);
-			if (time0 >= 0 && tm.tm_isdst > 0)
-				zoneint -= 3600;
+			if (st->zoness != 0)
+				sprintf(zonestr, "+%02d:%02d:%02d", (int) st->zonehh, (int) st->zonemm, (int) st->zoness);
+			else if (st->zonemm != 0)
+				sprintf(zonestr, "+%02d:%02d", (int) st->zonehh, (int) st->zonemm);
+			else
+				sprintf(zonestr, "+%02d", (int) st->zonehh);
+		}
+		else if (st->withZone < 0)
+		{
+			if (st->zoness != 0)
+				sprintf(zonestr, "-%02d:%02d:%02d", (int) st->zonehh, (int) st->zonemm, (int) st->zoness);
+			else if (st->zonemm != 0)
+				sprintf(zonestr, "-%02d:%02d", (int) st->zonehh, (int) st->zonemm);
+			else
+				sprintf(zonestr, "-%02d", (int) st->zonehh);
+		}
+#ifdef	TIMEZONE_GLOBAL
+		else if (st->y >= 1970)
+		{
+			long		zoneint;
+			int		zonehh, zonemm, zoness;
+			struct tm	tm;
+			time_t		time0;
+
+			zoneint = TIMEZONE_GLOBAL;
+			if (DAYLIGHT_GLOBAL)
+			{
+				tm.tm_year = st->y - 1900;
+				tm.tm_mon = st->m - 1;
+				tm.tm_mday = st->d;
+				tm.tm_hour = st->hh;
+				tm.tm_min = st->mm;
+				tm.tm_sec = st->ss;
+				tm.tm_isdst = -1;
+				time0 = mktime(&tm);
+				if (time0 >= 0 && tm.tm_isdst > 0)
+					zoneint -= SECS_ONEHOUR;
+			}
+			if (zoneint < 0)
+			{
+				zonehh = (-zoneint) / SECS_ONEHOUR;
+				zonemm = ((-zoneint) % SECS_ONEHOUR) / SECS_ONEMIN;
+				zoness = (-zoneint) % SECS_ONEMIN;
+				if (zoness != 0)
+					sprintf(zonestr, "+%02d:%02d:%02d", (int) zonehh, (int) zonemm, (int) zoness);
+				else if (zonemm != 0)
+					sprintf(zonestr, "+%02d:%02d", (int) zonehh, (int) zonemm);
+				else
+					sprintf(zonestr, "+%02d", (int) zonehh);
+			}
+			else
+			{
+				zonehh = zoneint / SECS_ONEHOUR;
+				zonemm = (zoneint % SECS_ONEHOUR) / SECS_ONEMIN;
+				zoness = zoneint % SECS_ONEMIN;
+				if (zoness != 0)
+					sprintf(zonestr, "-%02d:%02d:%02d", (int) zonehh, (int) zonemm, (int) zoness);
+				else if (zonemm != 0)
+					sprintf(zonestr, "-%02d:%02d", (int) zonehh, (int) zonemm);
+				else
+					sprintf(zonestr, "-%02d", (int) zonehh);
+			}
 		}
-		if (zoneint > 0)
-			sprintf(zonestr, "-%02d", (int) zoneint / 3600);
-		else
-			sprintf(zonestr, "+%02d", -(int) zoneint / 3600);
-	}
 #endif /* TIMEZONE_GLOBAL */
+	}
+
 	if (st->y < 0)
 		sprintf(str, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s BC", -st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr);
 	else
@@ -848,7 +1028,7 @@ mylog("null_cvt_date_string=%d\n", conn->connInfo.cvt_null_date_string);
 		/* a speicial handling for FOXPRO NULL -> NULL_STRING */
 		if (conn->connInfo.cvt_null_date_string > 0 &&
 		    (PG_TYPE_DATE == field_type ||
-		     PG_TYPE_DATETIME == field_type ||
+		     PG_TYPE_TIMESTAMP_W_TMZONE == field_type ||
 		     PG_TYPE_TIMESTAMP_NO_TMZONE == field_type) &&
 		    (SQL_C_CHAR == fCType ||
 #ifdef	UNICODE_SUPPORT
@@ -942,64 +1122,11 @@ mylog("null_cvt_date_string=%d\n", conn->connInfo.cvt_null_date_string);
 			break;
 
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
-		case PG_TYPE_TIMESTAMP:
-			std_time.fr = 0;
-			std_time.infinity = 0;
-			if (strnicmp(value, INFINITY_STRING, 8) == 0)
-			{
-				std_time.infinity = 1;
-				std_time.m = 12;
-				std_time.d = 31;
-				std_time.y = 9999;
-				std_time.hh = 23;
-				std_time.mm = 59;
-				std_time.ss = 59;
-			}
-			if (strnicmp(value, MINFINITY_STRING, 9) == 0)
-			{
-				std_time.infinity = -1;
-				std_time.m = 1;
-				std_time.d = 1;
-				// std_time.y = -4713;
-				std_time.y = -9999;
-				std_time.hh = 0;
-				std_time.mm = 0;
-				std_time.ss = 0;
-			}
-			if (strnicmp(value, "invalid", 7) != 0)
-			{
-				BOOL		bZone = (field_type != PG_TYPE_TIMESTAMP_NO_TMZONE && PG_VERSION_GE(conn, 7.2));
-				int			zone;
-
-				/*
-				 * sscanf(value, "%4d-%2d-%2d %2d:%2d:%2d", &std_time.y, &std_time.m,
-				 * &std_time.d, &std_time.hh, &std_time.mm, &std_time.ss);
-				 */
-				bZone = FALSE;	/* time zone stuff is unreliable */
-				timestamp2stime(value, &std_time, &bZone, &zone);
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
+			timestamp2stime(value, &std_time, use_local_time_zone && TIME_ZONE_TYPE(field_type));
 inolog("2stime fr=%d\n", std_time.fr);
-			}
-			else
-			{
-				/*
-				 * The timestamp is invalid so set something conspicuous,
-				 * like the epoch
-				 */
-				time_t	t = 0;
-#ifdef	HAVE_LOCALTIME_R
-				tim = localtime_r(&t, &tm);
-#else
-				tim = localtime(&t);
-#endif /* HAVE_LOCALTIME_R */
-				std_time.m = tim->tm_mon + 1;
-				std_time.d = tim->tm_mday;
-				std_time.y = tim->tm_year + 1900;
-				std_time.hh = tim->tm_hour;
-				std_time.mm = tim->tm_min;
-				std_time.ss = tim->tm_sec;
-			}
 			break;
 
 		case PG_TYPE_BOOL:
@@ -1170,16 +1297,20 @@ inolog("2stime fr=%d\n", std_time.fr);
 				break;
 
 			case PG_TYPE_ABSTIME:
-			case PG_TYPE_DATETIME:
+			case PG_TYPE_TIMESTAMP_W_TMZONE:
 			case PG_TYPE_TIMESTAMP_NO_TMZONE:
-			case PG_TYPE_TIMESTAMP:
+			case PG_TYPE_DEPRECATED_TIMESTAMP:
 				len = 19;
 				if (cbValueMax > len)
 				{
-					/* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
-						std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */
-					stime2timestamp(&std_time, rgbValueBindRow, FALSE,
-									PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0);
+					int	precmax = (int) cbValueMax - len - 2;
+					if (precision > 0 &&
+					    precision < precmax)
+						precmax = precision;
+
+					stime2timestamp(&std_time, rgbValueBindRow
+						, use_time_zone_expression && TIME_ZONE_TYPE(field_type)
+						, PG_VERSION_GE(conn, 7.2) ? precmax : 0);
 					len = strlen(rgbValueBindRow);
 				}
 				break;
@@ -2557,7 +2688,7 @@ Prepare_and_convert(StatementClass *stmt, QueryParse *qp, QueryBuild *qb)
 	if (QB_initialize(qb, qp->stmt_len, stmt, NULL) < 0)
 		return SQL_ERROR;
 	if (PROTOCOL_74(ci))
-		return prep_params(stmt, qp, qb, FALSE);
+		return prep_params(stmt, qp, qb, TRUE);
 	discardOutput = (0 != (qb->flags & FLGB_DISCARD_OUTPUT));
 	if (NOT_YET_PREPARED == stmt->prepared) /*  not yet prepared */
 	{
@@ -4498,7 +4629,7 @@ mylog("C_WCHAR=%s(%d)\n", buffer, used);
 mylog("cvt_null_date_string=%d pgtype=%d buf=%p\n", conn->connInfo.cvt_null_date_string, param_pgtype, buf);
 	if (conn->connInfo.cvt_null_date_string > 0 &&
 	    (PG_TYPE_DATE == param_pgtype ||
-	     PG_TYPE_DATETIME == param_pgtype ||
+	     PG_TYPE_TIMESTAMP_W_TMZONE == param_pgtype ||
 	     PG_TYPE_TIMESTAMP_NO_TMZONE == param_pgtype) &&
 	    NULL != buf &&
 	    (
@@ -4543,6 +4674,10 @@ mylog("buf=%p flag=%d\n", buf, qb->flags);
 				break;
 		}
 	}
+	if (0 == param_sqltype &&
+	    0 != param_pgtype &&
+	    NULL != qb->stmt)
+		param_sqltype = pgtype_to_concise_type(qb->stmt, param_pgtype, PG_STATIC);
 	switch (param_sqltype)
 	{
 		case SQL_CHAR:
@@ -4638,13 +4773,9 @@ mylog("buf=%p flag=%d\n", buf, qb->flags);
 				parse_datetime(cbuf, &st);
 			}
 
-			/*
-			 * sprintf(tmp, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", st.y,
-			 * st.m, st.d, st.hh, st.mm, st.ss);
-			 */
-			/* Time zone stuff is unreliable */
-			stime2timestamp(&st, tmp, USE_ZONE, PG_VERSION_GE(conn, 7.2) ? 6 : 0);
-			lastadd = "::timestamp";
+			stime2timestamp(&st, tmp 
+				, use_local_time_zone && TIME_ZONE_TYPE(param_pgtype)
+			 	, PG_VERSION_GE(conn, 7.2) ? 6 : 0);
 			CVT_APPEND_STR(qb, tmp);
 
 			break;
@@ -5368,8 +5499,13 @@ parse_datetime(const char *buf, SIMPLE_TIME *st)
 	y = m = d = hh = mm = ss = 0;
 	st->fr = 0;
 	st->infinity = 0;
+	st->invalid = 0;
+	st->withZone = 0;
 
-	/* escape sequence ? */
+	/*
+	 *	If input is an escape sequence
+	 *	skip until a quote comes.
+	 */
 	if (buf[0] == ODBC_ESCAPE_START)
 	{
 		while (*(++buf) && *buf != LITERAL_QUOTE);
@@ -5377,6 +5513,25 @@ parse_datetime(const char *buf, SIMPLE_TIME *st)
 			return FALSE;
 		buf++;
 	}
+
+	/* check hh:mm:ss first */
+	if (buf[2] == ':')
+	{
+		nf = sscanf(buf, "%2d:%2d:%2d", &hh, &mm, &ss);
+		if (nf == 2 || nf == 3)
+		{
+			st->hh = hh;
+			st->mm = mm;
+			st->ss = ss;
+
+			return TRUE;
+		}
+		return FALSE;
+	}
+
+	if (timestamp2stime(buf, st, use_local_time_zone))
+		return	TRUE;
+
 	if (buf[4] == '-')			/* year first */
 		nf = sscanf(buf, "%4d-%2d-%2d %2d:%2d:%2d", &y, &m, &d, &hh, &mm, &ss);
 	else
@@ -5408,16 +5563,6 @@ parse_datetime(const char *buf, SIMPLE_TIME *st)
 		return TRUE;
 	}
 
-	nf = sscanf(buf, "%2d:%2d:%2d", &hh, &mm, &ss);
-	if (nf == 2 || nf == 3)
-	{
-		st->hh = hh;
-		st->mm = mm;
-		st->ss = ss;
-
-		return TRUE;
-	}
-
 	return FALSE;
 }
 
diff --git a/convert.h b/convert.h
index 984eff5..476bd4e 100644
--- a/convert.h
+++ b/convert.h
@@ -28,7 +28,9 @@ extern "C" {
 
 typedef struct
 {
-	int		infinity;
+	char		infinity;
+	char		invalid;
+	char		withZone;
 	int			m;
 	int			d;
 	int			y;
@@ -36,6 +38,9 @@ typedef struct
 	int			mm;
 	int			ss;
 	int			fr;
+	char			zonehh;
+	char			zonemm;
+	char			zoness;
 } SIMPLE_TIME;
 
 int	copy_and_convert_field_bindinfo(StatementClass *stmt, OID field_type, int atttypmod, void *value, int col);
diff --git a/info.c b/info.c
index 81bfe6d..46937ff 100644
--- a/info.c
+++ b/info.c
@@ -2539,7 +2539,7 @@ mylog(" and the data=%s\n", attdef);
 				set_tuplefield_int4(&tuple[COLUMNS_DISPLAY_SIZE], column_size + 2);	/* sign+dec.point */
 			}
 		}
-		else if ((field_type == PG_TYPE_DATETIME) ||
+		else if ((field_type == PG_TYPE_TIMESTAMP_W_TMZONE) ||
 			(field_type == PG_TYPE_TIMESTAMP_NO_TMZONE))
 		{
 			if (PG_VERSION_GE(conn, 7.2))
@@ -2615,7 +2615,7 @@ mylog(" and the data=%s\n", attdef);
 		/* Subtract the header length */
 		switch (field_type)
 		{
-			case PG_TYPE_DATETIME:
+			case PG_TYPE_TIMESTAMP_W_TMZONE:
 			case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			case PG_TYPE_TIME:
 			case PG_TYPE_TIME_WITH_TMZONE:
diff --git a/parse.c b/parse.c
index 5aa7723..eef11d8 100644
--- a/parse.c
+++ b/parse.c
@@ -57,7 +57,7 @@ Int4 FI_precision(const FIELD_INFO *fi)
 	{
 		case PG_TYPE_NUMERIC:
 			return fi->column_size;
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			return fi->decimal_digits;
 	}
diff --git a/pgtypes.c b/pgtypes.c
index d7bde0a..ca8469f 100644
--- a/pgtypes.c
+++ b/pgtypes.c
@@ -54,7 +54,7 @@ OID pgtypes_defined[][2] = {
 			,{PG_TYPE_DATE, 0}
 			,{PG_TYPE_TIME, 0}
 			,{PG_TYPE_TIME_WITH_TMZONE, 0}
-			,{PG_TYPE_DATETIME, 0}
+			,{PG_TYPE_TIMESTAMP_W_TMZONE, 0}
 			,{PG_TYPE_ABSTIME, 0}
 			,{PG_TYPE_TIMESTAMP_NO_TMZONE, 0}
 			,{PG_TYPE_TIMESTAMP, 0}
@@ -619,9 +619,9 @@ pgtype_attr_to_concise_type(const ConnectionClass *conn, OID type, int atttypmod
 #endif /* ODBCVER */
 			return SQL_TIME;
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 #if (ODBCVER >= 0x0300)
 			if (EN_is_odbc3(env))
 				return SQL_TYPE_TIMESTAMP;
@@ -768,9 +768,9 @@ pgtype_attr_to_ctype(const ConnectionClass *conn, OID type, int atttypmod)
 #endif /* ODBCVER */
 			return SQL_C_TIME;
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 #if (ODBCVER >= 0x0300)
 			if (EN_is_odbc3(env))
 				return SQL_C_TYPE_TIMESTAMP;
@@ -867,7 +867,7 @@ inolog("pgtype_to_name int4\n");
 			return "time";
 		case PG_TYPE_ABSTIME:
 			return "abstime";
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 			if (PG_VERSION_GT(conn, 7.1))
 				return "timestamptz";
 			else if (PG_VERSION_LT(conn, 7.0))
@@ -876,7 +876,7 @@ inolog("pgtype_to_name int4\n");
 				return "timestamp";
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			return "timestamp without time zone";
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 			return "timestamp";
 		case PG_TYPE_MONEY:
 			return "money";
@@ -994,9 +994,9 @@ pgtype_attr_column_size(const ConnectionClass *conn, OID type, int atttypmod, in
 			return 8;
 
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 			return 22;
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			/* return 22; */
 			return getTimestampColumnSizeX(conn, type, atttypmod);
@@ -1039,7 +1039,7 @@ pgtype_attr_precision(const ConnectionClass *conn, OID type, int atttypmod, int
 	{
 		case PG_TYPE_NUMERIC:
 			return getNumericColumnSizeX(conn, type, atttypmod, adtsize_or_longest, handle_unknown_size_as);
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			return getTimestampDecimalDigitsX(conn, type, atttypmod);
 #ifdef	PG_INTERVAL_AS_SQL_INTERVAL
@@ -1138,8 +1138,8 @@ pgtype_attr_buffer_length(const ConnectionClass *conn, OID type, int atttypmod,
 			return 6;		/* sizeof(DATE(TIME)_STRUCT) */
 
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_DATETIME:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			return 16;		/* sizeof(TIMESTAMP_STRUCT) */
 
@@ -1223,9 +1223,9 @@ pgtype_attr_desclength(const ConnectionClass *conn, OID type, int atttypmod, int
 		case PG_TYPE_DATE:
 		case PG_TYPE_TIME:
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 		case PG_TYPE_VARCHAR:
 		case PG_TYPE_BPCHAR:
 			return pgtype_attr_column_size(conn, type, atttypmod, adtsize_or_longestlen, handle_unknown_size_as);
@@ -1254,9 +1254,9 @@ pgtype_attr_decimal_digits(const ConnectionClass *conn, OID type, int atttypmod,
 			 * "yyyy-mm=dd hh:mm:ss[.f...]"
 			 */
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 			return 0;
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			/* return 0; */
 			return getTimestampDecimalDigitsX(conn, type, atttypmod);
@@ -1413,7 +1413,7 @@ sqltype_to_pgtype(const ConnectionClass *conn, SQLSMALLINT fSqlType)
 #if (ODBCVER >= 0x0300)
 		case SQL_TYPE_TIMESTAMP:
 #endif /* ODBCVER */
-			pgType = PG_TYPE_DATETIME;
+			pgType = PG_TYPE_TIMESTAMP_W_TMZONE;
 			break;
 
 		case SQL_VARBINARY:
@@ -1940,8 +1940,8 @@ pgtype_min_decimal_digits(const ConnectionClass *conn, OID type)
 		case PG_TYPE_MONEY:
 		case PG_TYPE_BOOL:
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_TIMESTAMP:
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 		case PG_TYPE_NUMERIC:
 			return 0;
@@ -1968,9 +1968,9 @@ pgtype_max_decimal_digits(const ConnectionClass *conn, OID type)
 		case PG_TYPE_MONEY:
 		case PG_TYPE_BOOL:
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 			return 0;
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			return 38;
 		case PG_TYPE_NUMERIC:
@@ -2053,9 +2053,9 @@ pgtype_auto_increment(const ConnectionClass *conn, OID type)
 		case PG_TYPE_TIME_WITH_TMZONE:
 		case PG_TYPE_TIME:
 		case PG_TYPE_ABSTIME:
-		case PG_TYPE_DATETIME:
+		case PG_TYPE_TIMESTAMP_W_TMZONE:
 		case PG_TYPE_TIMESTAMP_NO_TMZONE:
-		case PG_TYPE_TIMESTAMP:
+		case PG_TYPE_DEPRECATED_TIMESTAMP:
 			return FALSE;
 
 		default:
diff --git a/pgtypes.h b/pgtypes.h
index 6a9eead..5242c08 100644
--- a/pgtypes.h
+++ b/pgtypes.h
@@ -67,11 +67,11 @@
 #define PG_TYPE_VARCHAR			1043
 #define PG_TYPE_DATE			1082
 #define PG_TYPE_TIME			1083
-#define PG_TYPE_TIMESTAMP_NO_TMZONE	1114		/* since 7.2 */
-#define PG_TYPE_DATETIME		1184
+#define PG_TYPE_TIMESTAMP_NO_TMZONE	1114	/* since 7.2 */
+#define PG_TYPE_TIMESTAMP_W_TMZONE	1184	/* DATETIME until 7.2 */
 #define PG_TYPE_INTERVAL		1186
-#define PG_TYPE_TIME_WITH_TMZONE	1266		/* since 7.1 */
-#define PG_TYPE_TIMESTAMP		1296	/* deprecated since 7.0 */
+#define PG_TYPE_TIME_WITH_TMZONE	1266	/* since 7.1 */
+#define PG_TYPE_DEPRECATED_TIMESTAMP	1296	/* deprecated since 7.0 */
 #define PG_TYPE_BIT			1560
 #define PG_TYPE_NUMERIC			1700
 #define PG_TYPE_REFCURSOR		1790
