diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/method/misc/OSQLMethodFormat.java b/core/src/main/java/com/orientechnologies/orient/core/sql/method/misc/OSQLMethodFormat.java
index <HASH>..<HASH> 100644
--- a/core/src/main/java/com/orientechnologies/orient/core/sql/method/misc/OSQLMethodFormat.java
+++ b/core/src/main/java/com/orientechnologies/orient/core/sql/method/misc/OSQLMethodFormat.java
@@ -42,8 +42,8 @@ public class OSQLMethodFormat extends OAbstractSQLMethod {
 
     final Object v = getParameterValue(iRecord, iMethodParams[0].toString());
     if (v != null) {
-      if (ioResult instanceof Long)
-        ioResult = new Date((Long) ioResult);
+      if (ioResult instanceof Number)
+        ioResult = new Date(((Long) ioResult).longValue());
 
       if (ioResult instanceof Date) {
         final SimpleDateFormat format = new SimpleDateFormat(v.toString());
.format(): supported conversion from any Number