syncbase: syncQL: time functions: Time,Now,Year,Month,Day,Hour,Minute,Second,Nanosecond,Weekday,YearDay

New functions:

Time(<go-style-layout-string>, <location-string>): time
    e.g., Time("2006-01-02 15:04:05 MST", "2015-03-17 11:14:04 PDT")

Year(<time>, <string-location>): integer year
    e.g., Year(v.InvoiceDate, ""America/Los_Angeles")

Month(<time>, <string-location>): integer month
    e.g., Year(v.InvoiceDate, ""America/Los_Angeles")

The following follow the same pattern as Year and Month
    Day
    Hour
    Minute
    Second
    Nanosecond
    Weekday
    YearDay

Kept time functions:
Now() returns current time (and already existed).

Deleted time functions:
The previous library of time functions has been deleted (except Now() was kept).
    Date
    DateTime
    Y
    YM
    YMD
    YMDH
    YMDHM
    YMDHMS

Change-Id: I66e0e0099cb72d2c6c2f31ede484e0cd8604af2f
diff --git a/v23/syncbase/nosql/exec_test/exec_test.go b/v23/syncbase/nosql/exec_test/exec_test.go
index 1ddc151..f504744 100644
--- a/v23/syncbase/nosql/exec_test/exec_test.go
+++ b/v23/syncbase/nosql/exec_test/exec_test.go
@@ -667,7 +667,7 @@
 		// Test functions.
 		{
 			// Select invoice records where date is 2015-03-17
-			"select v from Customer where Type(v) like \"%.Invoice\" and YMD(v.InvoiceDate, \"America/Los_Angeles\") = Date(\"2015-03-17 PDT\")",
+			"select v from Customer where Type(v) like \"%.Invoice\" and Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17",
 			[]string{"v"},
 			[][]*vdl.Value{
 				[]*vdl.Value{customerEntries[5].value},
@@ -676,7 +676,7 @@
 		},
 		{
 			// Now will always be > 2012, so all customer records will be returned.
-			"select v from Customer where Now() > Date(\"2012-03-17 PDT\")",
+			"select v from Customer where Now() > Time(\"2006-01-02 MST\", \"2012-03-17 PDT\")",
 			[]string{"v"},
 			[][]*vdl.Value{
 				[]*vdl.Value{customerEntries[0].value},
@@ -696,7 +696,7 @@
 			// Note: this wouldn't work for March as daylight saving occurs March 8
 			// and causes comparisons for those days to be off 1 hour.
 			// It would work to use UTC -- see next test.
-			"select k from Customer where YM(v.InvoiceDate, \"America/Los_Angeles\") = YM(Date(\"2015-04-01 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 4",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[7].key)},
@@ -705,7 +705,7 @@
 		},
 		{
 			// Select March 2015 UTC invoices.
-			"select k from Customer where YM(v.InvoiceDate, \"UTC\") = YM(Date(\"2015-03-01 UTC\"), \"UTC\")",
+			"select k from Customer where Year(v.InvoiceDate, \"UTC\") = 2015 and Month(v.InvoiceDate, \"UTC\") = 3",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[3].key)},
@@ -715,7 +715,7 @@
 		},
 		{
 			// Select 2015 UTC invoices.
-			"select k from Customer where Y(v.InvoiceDate, \"UTC\") = Y(Date(\"2015-01-01 UTC\"), \"UTC\")",
+			"select k from Customer where Year(v.InvoiceDate, \"UTC\") = 2015",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[1].key)},
@@ -729,7 +729,7 @@
 		},
 		{
 			// Select the Mar 17 2015 11:14:04 America/Los_Angeles invoice.
-			"select k from Customer where v.InvoiceDate = DateTime(\"2015-03-17 11:14:04 PDT\")",
+			"select k from Customer where v.InvoiceDate = Time(\"2006-01-02 15:04:05 MST\", \"2015-03-17 11:14:04 PDT\")",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[5].key)},
@@ -737,7 +737,7 @@
 		},
 		{
 			// Select invoices in the minute Mar 17 2015 11:14 America/Los_Angeles invoice.
-			"select k from Customer where YMDHM(v.InvoiceDate, \"America/Los_Angeles\") = YMDHM(DateTime(\"2015-03-17 11:14:00 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17 and Hour(v.InvoiceDate, \"America/Los_Angeles\") = 11 and Minute(v.InvoiceDate, \"America/Los_Angeles\") = 14",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[5].key)},
@@ -745,7 +745,7 @@
 		},
 		{
 			// Select invoices in the hour Mar 17 2015 11 hundred America/Los_Angeles invoice.
-			"select k from Customer where YMDH(v.InvoiceDate, \"America/Los_Angeles\") = YMDH(DateTime(\"2015-03-17 11:00:00 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17 and Hour(v.InvoiceDate, \"America/Los_Angeles\") = 11",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[5].key)},
@@ -753,7 +753,7 @@
 		},
 		{
 			// Select invoices on the day Mar 17 2015 America/Los_Angeles invoice.
-			"select k from Customer where YMD(v.InvoiceDate, \"America/Los_Angeles\") = YMD(Date(\"2015-03-17 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(customerEntries[5].key)},
@@ -784,10 +784,10 @@
 			},
 		},
 		// Select clause functions.
-		// Date function
+		// Time function
 		{
-			"select Date(\"2015-07-01 PDT\") from Customer",
-			[]string{"Date"},
+			"select Time(\"2006-01-02 MST\", \"2015-07-01 PDT\") from Customer",
+			[]string{"Time"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01)},
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01)},
@@ -801,10 +801,10 @@
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01)},
 			},
 		},
-		// DateTime function
+		// Time function
 		{
-			"select DateTime(\"2015-07-01 01:23:45 PDT\") from Customer",
-			[]string{"DateTime"},
+			"select Time(\"2006-01-02 15:04:05 MST\", \"2015-07-01 01:23:45 PDT\") from Customer",
+			[]string{"Time"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01_01_23_45)},
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01_01_23_45)},
@@ -838,83 +838,83 @@
 				[]*vdl.Value{vdl.ValueOf("JOHN STEED")},
 			},
 		},
-		// YMDHMS function
+		// Second function
 		{
-			"select k, YMDHMS(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Second(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMDHMS",
+				"Second",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12_22_16_06)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(6))},
 			},
 		},
-		// YMDHM function
+		// Minute function
 		{
-			"select k, YMDHM(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Minute(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMDHM",
+				"Minute",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12_22_16)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(16))},
 			},
 		},
-		// YMDH function
+		// Hour function
 		{
-			"select k, YMDH(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Hour(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMDH",
+				"Hour",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12_22)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(22))},
 			},
 		},
-		// YMD function
+		// Day function
 		{
-			"select k, YMD(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Day(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMD",
+				"Day",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(12))},
 			},
 		},
-		// YM function
+		// Month function
 		{
-			"select k, YM(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Month(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YM",
+				"Month",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(4))},
 			},
 		},
-		// Y function
+		// Year function
 		{
-			"select k, Y(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
+			"select k, Year(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
 			[]string{
 				"k",
-				"Y",
+				"Year",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("001001"), vdl.ValueOf(t2015)},
+				[]*vdl.Value{vdl.ValueOf("001001"), vdl.ValueOf(int64(2015))},
 			},
 		},
 		// Nested functions
 		{
-			"select Y(YM(YMD(YMDH(YMDHM(YMDHMS(v.InvoiceDate, \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\")  from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
-			[]string{"Y"},
+			"select Year(Time(\"2006-01-02 15:04:05 MST\", \"2015-07-01 01:23:45 PDT\"), \"America/Los_Angeles\")  from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
+			[]string{"Year"},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf(t2015)},
+				[]*vdl.Value{vdl.ValueOf(int64(2015))},
 			},
 		},
 		// Bad arg to function.  Expression is false.
 		{
-			"select v from Customer where Type(v) like \"%.Invoice\" and YMD(v.InvoiceDate, v.Foo) = v.InvoiceDate",
+			"select v from Customer where Type(v) like \"%.Invoice\" and Day(v.InvoiceDate, v.Foo) = v.InvoiceDate",
 			[]string{"v"},
 			[][]*vdl.Value{},
 		},
diff --git a/v23/syncbase/nosql/internal/query/query_checker/query_checker_test.go b/v23/syncbase/nosql/internal/query/query_checker/query_checker_test.go
index 5188c52..2e2057d 100644
--- a/v23/syncbase/nosql/internal/query/query_checker/query_checker_test.go
+++ b/v23/syncbase/nosql/internal/query/query_checker/query_checker_test.go
@@ -150,7 +150,7 @@
 		{"select v from Customer where v.ZipCode IS NOT NIL"},
 		{"select v from Customer where Now() < 10"},
 		{"select Now() from Customer"},
-		{"select Date(\"2015-06-01 PST\"), DateTime(\"2015-06-01 12:34:56 PST\"), Y(YM(YMD(YMDH(YMDHM(YMDHMS(Now(), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\") from Customer"},
+		{"select Time(\"2006-01-02 MST\", \"2015-06-01 PST\"), Time(\"2006-01-02 15:04:05 MST\", \"2015-06-01 12:34:56 PST\"), Year(Now(), \"America/Los_Angeles\") from Customer"},
 	}
 
 	for _, test := range basic {
@@ -432,17 +432,17 @@
 		{"select v from Customer where v.ZipCode is not 94303", syncql.NewErrIsIsNotRequireRhsNil(db.GetContext(), 46)},
 		{"select v from Customer where v.ZipCode is not true", syncql.NewErrIsIsNotRequireRhsNil(db.GetContext(), 46)},
 		{"select v from Customer where v.ZipCode is not 943.03", syncql.NewErrIsIsNotRequireRhsNil(db.GetContext(), 46)},
-		{"select v from Customer where Type(v) = \"Customer\" and Y(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 71, errors.New("unknown time zone ABC"))},
-		{"select v from Customer where Type(v) = \"Customer\" and YM(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 72, errors.New("unknown time zone ABC"))},
-		{"select v from Customer where Type(v) = \"Customer\" and YMD(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 73, errors.New("unknown time zone ABC"))},
-		{"select v from Customer where Type(v) = \"Customer\" and YMDH(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 74, errors.New("unknown time zone ABC"))},
-		{"select v from Customer where Type(v) = \"Customer\" and YMDHM(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 75, errors.New("unknown time zone ABC"))},
-		{"select v from Customer where Type(v) = \"Customer\" and YMDHMS(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 76, errors.New("unknown time zone ABC"))},
+		{"select v from Customer where Type(v) = \"Customer\" and Year(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 74, errors.New("unknown time zone ABC"))},
+		{"select v from Customer where Type(v) = \"Customer\" and Month(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 75, errors.New("unknown time zone ABC"))},
+		{"select v from Customer where Type(v) = \"Customer\" and Day(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 73, errors.New("unknown time zone ABC"))},
+		{"select v from Customer where Type(v) = \"Customer\" and Hour(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 74, errors.New("unknown time zone ABC"))},
+		{"select v from Customer where Type(v) = \"Customer\" and Minute(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 76, errors.New("unknown time zone ABC"))},
+		{"select v from Customer where Type(v) = \"Customer\" and Second(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrLocationConversionError(db.GetContext(), 76, errors.New("unknown time zone ABC"))},
 		{"select v from Customer where Type(v) = \"Customer\" and Now(v.InvoiceDate, \"ABC\") = 2015", syncql.NewErrFunctionArgCount(db.GetContext(), 54, "Now", 0, 2)},
 		{"select v from Customer where Type(v) = \"Customer\" and Lowercase(v.Name, 2) = \"smith\"", syncql.NewErrFunctionArgCount(db.GetContext(), 54, "Lowercase", 1, 2)},
 		{"select v from Customer where Type(v) = \"Customer\" and Uppercase(v.Name, 2) = \"SMITH\"", syncql.NewErrFunctionArgCount(db.GetContext(), 54, "Uppercase", 1, 2)},
-		{"select Date() from Customer", syncql.NewErrFunctionArgCount(db.GetContext(), 7, "Date", 1, 0)},
-		{"select Y(v.InvoiceDate, \"Foo\") from Customer where Type(v) = \"Invoice\"", syncql.NewErrLocationConversionError(db.GetContext(), 24, errors.New("unknown time zone Foo"))},
+		{"select Time() from Customer", syncql.NewErrFunctionArgCount(db.GetContext(), 7, "Time", 2, 0)},
+		{"select Year(v.InvoiceDate, \"Foo\") from Customer where Type(v) = \"Invoice\"", syncql.NewErrLocationConversionError(db.GetContext(), 27, errors.New("unknown time zone Foo"))},
 		{"select K from Customer where Type(v) = \"Invoice\"", syncql.NewErrDidYouMeanLowercaseK(db.GetContext(), 7)},
 		{"select V from Customer where Type(v) = \"Invoice\"", syncql.NewErrDidYouMeanLowercaseV(db.GetContext(), 7)},
 		{"select k from Customer where K = \"001\"", syncql.NewErrDidYouMeanLowercaseK(db.GetContext(), 29)},
diff --git a/v23/syncbase/nosql/internal/query/query_functions/date_funcs.go b/v23/syncbase/nosql/internal/query/query_functions/date_funcs.go
index 2db74f0..6ec82e8 100644
--- a/v23/syncbase/nosql/internal/query/query_functions/date_funcs.go
+++ b/v23/syncbase/nosql/internal/query/query_functions/date_funcs.go
@@ -4,6 +4,8 @@
 
 package query_functions
 
+// TODO(jkline): Probably rename this file to time_functions.go
+
 import (
 	"time"
 
@@ -52,178 +54,127 @@
 	}
 }
 
-// Input: "YYYY-MM-DD TZ"
-// "2015-03-17 PDT"
-func date(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	dateStrOp, err := conversions.ConvertValueToString(args[0])
+// Time(layout, value string)
+// e.g., Time("Mon Jan 2 15:04:05 -0700 MST 2006", "Tue Aug 25 10:01:00 -0700 PDT 2015")
+// e.g., Time("Jan 2 15:04 MST 2006", "Aug 25 10:01 PDT 2015")
+func timeFunc(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	layoutOp, err := conversions.ConvertValueToString(args[0])
+	if err != nil {
+		return nil, err
+	}
+	valueOp, err := conversions.ConvertValueToString(args[1])
 	if err != nil {
 		return nil, err
 	}
 	// Mon Jan 2 15:04:05 -0700 MST 2006
-	tim, err := time.Parse("2006-01-02 MST", dateStrOp.Str)
+	tim, err := time.Parse(layoutOp.Str, valueOp.Str)
 	if err != nil {
 		return nil, err
 	}
 	return makeTimeOp(off, tim), nil
 }
 
-// "YYYY-MM-DD HH:MI:SS TZ"
-// "2015-03-17 13:22:17 PDT"
-func dateTime(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	dateStrOp, err := conversions.ConvertValueToString(args[0])
-	if err != nil {
-		return nil, err
-	}
-	// Mon Jan 2 15:04:05 -0700 MST 2006
-	tim, err := time.Parse("2006-01-02 15:04:05 MST", dateStrOp.Str)
-	if err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
-// y(v.InvoiceDate, "America/Los_Angeles")
-func y(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	var timeOp *query_parser.Operand
-	var locOp *query_parser.Operand
-	var err error
-	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
-		return nil, err
-	}
-	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
-		return nil, err
-	}
-	var loc *time.Location
-	if loc, err = time.LoadLocation(locOp.Str); err != nil {
-		return nil, err
-	}
-	dateStr := timeOp.Time.In(loc).Format("2006 MST")
-	var tim time.Time
-	if tim, err = time.Parse("2006 MST", dateStr); err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
-// ym(v.InvoiceDate, "America/Los_Angeles")
-func ym(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	var timeOp *query_parser.Operand
-	var locOp *query_parser.Operand
-	var err error
-	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
-		return nil, err
-	}
-	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
-		return nil, err
-	}
-	var loc *time.Location
-	if loc, err = time.LoadLocation(locOp.Str); err != nil {
-		return nil, err
-	}
-	dateStr := timeOp.Time.In(loc).Format("200601 MST")
-	var tim time.Time
-	if tim, err = time.Parse("200601 MST", dateStr); err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
-// ymd(v.InvoiceDate, "America/Los_Angeles")
-func ymd(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	var timeOp *query_parser.Operand
-	var locOp *query_parser.Operand
-	var err error
-	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
-		return nil, err
-	}
-	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
-		return nil, err
-	}
-	var loc *time.Location
-	if loc, err = time.LoadLocation(locOp.Str); err != nil {
-		return nil, err
-	}
-	dateStr := timeOp.Time.In(loc).Format("20060102 MST")
-	var tim time.Time
-	if tim, err = time.Parse("20060102 MST", dateStr); err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
-// ymdh(v.InvoiceDate, "America/Los_Angeles")
-func ymdh(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	var timeOp *query_parser.Operand
-	var locOp *query_parser.Operand
-	var err error
-	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
-		return nil, err
-	}
-	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
-		return nil, err
-	}
-	var loc *time.Location
-	if loc, err = time.LoadLocation(locOp.Str); err != nil {
-		return nil, err
-	}
-	dateStr := timeOp.Time.In(loc).Format("20060102 15 MST")
-	var tim time.Time
-	if tim, err = time.Parse("20060102 15 MST", dateStr); err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
-// ymdhm(v.InvoiceDate, "America/Los_Angeles")
-func ymdhm(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	var timeOp *query_parser.Operand
-	var locOp *query_parser.Operand
-	var err error
-	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
-		return nil, err
-	}
-	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
-		return nil, err
-	}
-	var loc *time.Location
-	if loc, err = time.LoadLocation(locOp.Str); err != nil {
-		return nil, err
-	}
-	dateStr := timeOp.Time.In(loc).Format("20060102 15:04 MST")
-	var tim time.Time
-	if tim, err = time.Parse("20060102 15:04 MST", dateStr); err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
-// ymdhms(v.InvoiceDate, "America/Los_Angeles")
-func ymdhms(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
-	var timeOp *query_parser.Operand
-	var locOp *query_parser.Operand
-	var err error
-	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
-		return nil, err
-	}
-	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
-		return nil, err
-	}
-	var loc *time.Location
-	if loc, err = time.LoadLocation(locOp.Str); err != nil {
-		return nil, err
-	}
-	dateStr := timeOp.Time.In(loc).Format("20060102 15:04:05 MST")
-	var tim time.Time
-	if tim, err = time.Parse("20060102 15:04:05 MST", dateStr); err != nil {
-		return nil, err
-	}
-	return makeTimeOp(off, tim), nil
-}
-
 // now()
 func now(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
 	return makeTimeOp(off, time.Now()), nil
 }
+func timeInLocation(db query_db.Database, off int64, args []*query_parser.Operand) (time.Time, error) {
+	var timeOp *query_parser.Operand
+	var locOp *query_parser.Operand
+	var err error
+	if timeOp, err = conversions.ConvertValueToTime(args[0]); err != nil {
+		return time.Time{}, err
+	}
+	if locOp, err = conversions.ConvertValueToString(args[1]); err != nil {
+		return time.Time{}, err
+	}
+	var loc *time.Location
+	if loc, err = time.LoadLocation(locOp.Str); err != nil {
+		return time.Time{}, err
+	}
+	return timeOp.Time.In(loc), nil
+}
+
+// Year(v.InvoiceDate, "America/Los_Angeles")
+func year(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Year())), nil
+	}
+}
+
+// Month(v.InvoiceDate, "America/Los_Angeles")
+func month(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Month())), nil
+	}
+}
+
+// Day(v.InvoiceDate, "America/Los_Angeles")
+func day(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Day())), nil
+	}
+}
+
+// Hour(v.InvoiceDate, "America/Los_Angeles")
+func hour(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Hour())), nil
+	}
+}
+
+// Minute(v.InvoiceDate, "America/Los_Angeles")
+func minute(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Minute())), nil
+	}
+}
+
+// Second(v.InvoiceDate, "America/Los_Angeles")
+func second(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Second())), nil
+	}
+}
+
+// Nanosecond(v.InvoiceDate, "America/Los_Angeles")
+func nanosecond(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Nanosecond())), nil
+	}
+}
+
+// Weekday(v.InvoiceDate, "America/Los_Angeles")
+func weekday(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.Weekday())), nil
+	}
+}
+
+// YearDay(v.InvoiceDate, "America/Los_Angeles")
+func yearDay(db query_db.Database, off int64, args []*query_parser.Operand) (*query_parser.Operand, error) {
+	if tim, err := timeInLocation(db, off, args); err != nil {
+		return nil, err
+	} else {
+		return makeIntOp(off, int64(tim.YearDay())), nil
+	}
+}
 
 func makeTimeOp(off int64, tim time.Time) *query_parser.Operand {
 	var o query_parser.Operand
diff --git a/v23/syncbase/nosql/internal/query/query_functions/query_functions.go b/v23/syncbase/nosql/internal/query/query_functions/query_functions.go
index e051a03..d94170f 100644
--- a/v23/syncbase/nosql/internal/query/query_functions/query_functions.go
+++ b/v23/syncbase/nosql/internal/query/query_functions/query_functions.go
@@ -32,15 +32,18 @@
 func init() {
 	functions = make(map[string]function)
 
-	functions["Date"] = function{[]query_parser.OperandType{query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, date, nil}
-	functions["DateTime"] = function{[]query_parser.OperandType{query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, dateTime, nil}
-	functions["Y"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, y, secondArgLocationCheck}
-	functions["YM"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, ym, secondArgLocationCheck}
-	functions["YMD"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, ymd, secondArgLocationCheck}
-	functions["YMDH"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, ymdh, secondArgLocationCheck}
-	functions["YMDHM"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, ymdhm, secondArgLocationCheck}
-	functions["YMDHMS"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, ymdhms, secondArgLocationCheck}
+	// Time Functions
+	functions["Time"] = function{[]query_parser.OperandType{query_parser.TypStr, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypTime, timeFunc, nil}
 	functions["Now"] = function{[]query_parser.OperandType{}, false, query_parser.TypNil, query_parser.TypTime, now, nil}
+	functions["Year"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, year, secondArgLocationCheck}
+	functions["Month"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, month, secondArgLocationCheck}
+	functions["Day"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, day, secondArgLocationCheck}
+	functions["Hour"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, hour, secondArgLocationCheck}
+	functions["Minute"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, minute, secondArgLocationCheck}
+	functions["Second"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, second, secondArgLocationCheck}
+	functions["Nanosecond"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, nanosecond, secondArgLocationCheck}
+	functions["Weekday"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, weekday, secondArgLocationCheck}
+	functions["YearDay"] = function{[]query_parser.OperandType{query_parser.TypTime, query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypInt, yearDay, secondArgLocationCheck}
 
 	// String Functions
 	functions["Lowercase"] = function{[]query_parser.OperandType{query_parser.TypStr}, false, query_parser.TypNil, query_parser.TypStr, lowerCase, nil}
diff --git a/v23/syncbase/nosql/internal/query/query_functions/query_functions_test.go b/v23/syncbase/nosql/internal/query/query_functions/query_functions_test.go
index 621f8d4..5720522 100644
--- a/v23/syncbase/nosql/internal/query/query_functions/query_functions_test.go
+++ b/v23/syncbase/nosql/internal/query/query_functions/query_functions_test.go
@@ -57,32 +57,32 @@
 	err  error
 }
 
-var t_2015 time.Time
-var t_2015_06 time.Time
 var t_2015_06_21 time.Time
-var t_2015_06_21_01 time.Time
-var t_2015_06_21_01_23 time.Time
 var t_2015_06_21_01_23_45 time.Time
+var t_2015_06_09_01_23_45_8327 time.Time
 
 func init() {
-	// Mon Jan 2 15:04:05 -0700 MST 2006
-	t_2015, _ = time.Parse("2006 MST", "2015 PDT")
-	t_2015_06, _ = time.Parse("2006/01 MST", "2015/06 PDT")
 	t_2015_06_21, _ = time.Parse("2006/01/02 MST", "2015/06/21 PDT")
-	t_2015_06_21_01, _ = time.Parse("2006/01/02 15 MST", "2015/06/21 01 PDT")
-	t_2015_06_21_01_23, _ = time.Parse("2006/01/02 15:04 MST", "2015/06/21 01:23 PDT")
+
 	t_2015_06_21_01_23_45, _ = time.Parse("2006/01/02 15:04:05 MST", "2015/06/21 01:23:45 PDT")
+
+	loc, _ := time.LoadLocation("America/Los_Angeles")
+	t_2015_06_09_01_23_45_8327 = time.Date(2015, 6, 9, 1, 23, 45, 8327, loc)
 }
 
 func TestFunctions(t *testing.T) {
 	tests := []functionsTest{
-		// Date
+		// Time
 		functionsTest{
 			&query_parser.Function{
-				Name: "Date",
+				Name: "Time",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
+						Str:  "2006-01-02 MST",
+					},
+					&query_parser.Operand{
+						Type: query_parser.TypStr,
 						Str:  "2015-06-21 PDT",
 					},
 				},
@@ -96,6 +96,10 @@
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
+					Str:  "2006-01-02 MST",
+				},
+				&query_parser.Operand{
+					Type: query_parser.TypStr,
 					Str:  "2015-06-21 PDT",
 				},
 			},
@@ -104,13 +108,17 @@
 				Time: t_2015_06_21,
 			},
 		},
-		// DateTime
+		// Time
 		functionsTest{
 			&query_parser.Function{
-				Name: "DateTime",
+				Name: "Time",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
+						Str:  "2006-01-02 15:04:05 MST",
+					},
+					&query_parser.Operand{
+						Type: query_parser.TypStr,
 						Str:  "2015-06-21 01:23:45 PDT",
 					},
 				},
@@ -124,6 +132,10 @@
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
+					Str:  "2006-01-02 15:04:05 MST",
+				},
+				&query_parser.Operand{
+					Type: query_parser.TypStr,
 					Str:  "2015-06-21 01:23:45 PDT",
 				},
 			},
@@ -132,14 +144,14 @@
 				Time: t_2015_06_21_01_23_45,
 			},
 		},
-		// Y
+		// Year
 		functionsTest{
 			&query_parser.Function{
-				Name: "Y",
+				Name: "Year",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypTime,
-						Time: t_2015_06_21_01_23_45,
+						Time: t_2015_06_09_01_23_45_8327,
 					},
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
@@ -147,17 +159,17 @@
 					},
 				},
 				ArgTypes: []query_parser.OperandType{
-					query_parser.TypStr,
+					query_parser.TypTime,
 					query_parser.TypStr,
 				},
-				RetType:  query_parser.TypTime,
+				RetType:  query_parser.TypInt,
 				Computed: false,
 				RetValue: nil,
 			},
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypTime,
-					Time: t_2015_06_21_01_23_45,
+					Time: t_2015_06_09_01_23_45_8327,
 				},
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
@@ -165,18 +177,18 @@
 				},
 			},
 			&query_parser.Operand{
-				Type: query_parser.TypTime,
-				Time: t_2015,
+				Type: query_parser.TypInt,
+				Int:  2015,
 			},
 		},
-		// YM
+		// Month
 		functionsTest{
 			&query_parser.Function{
-				Name: "YM",
+				Name: "Month",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypTime,
-						Time: t_2015_06_21_01_23_45,
+						Time: t_2015_06_09_01_23_45_8327,
 					},
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
@@ -184,17 +196,17 @@
 					},
 				},
 				ArgTypes: []query_parser.OperandType{
-					query_parser.TypStr,
+					query_parser.TypTime,
 					query_parser.TypStr,
 				},
-				RetType:  query_parser.TypTime,
+				RetType:  query_parser.TypInt,
 				Computed: false,
 				RetValue: nil,
 			},
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypTime,
-					Time: t_2015_06_21_01_23_45,
+					Time: t_2015_06_09_01_23_45_8327,
 				},
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
@@ -202,18 +214,18 @@
 				},
 			},
 			&query_parser.Operand{
-				Type: query_parser.TypTime,
-				Time: t_2015_06,
+				Type: query_parser.TypInt,
+				Int:  6,
 			},
 		},
-		// YMD
+		// Day
 		functionsTest{
 			&query_parser.Function{
-				Name: "YMD",
+				Name: "Day",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypTime,
-						Time: t_2015_06_21_01_23_45,
+						Time: t_2015_06_09_01_23_45_8327,
 					},
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
@@ -221,17 +233,17 @@
 					},
 				},
 				ArgTypes: []query_parser.OperandType{
-					query_parser.TypStr,
+					query_parser.TypTime,
 					query_parser.TypStr,
 				},
-				RetType:  query_parser.TypTime,
+				RetType:  query_parser.TypInt,
 				Computed: false,
 				RetValue: nil,
 			},
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypTime,
-					Time: t_2015_06_21_01_23_45,
+					Time: t_2015_06_09_01_23_45_8327,
 				},
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
@@ -239,18 +251,18 @@
 				},
 			},
 			&query_parser.Operand{
-				Type: query_parser.TypTime,
-				Time: t_2015_06_21,
+				Type: query_parser.TypInt,
+				Int:  9,
 			},
 		},
-		// YMDH
+		// Hour
 		functionsTest{
 			&query_parser.Function{
-				Name: "YMDH",
+				Name: "Hour",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypTime,
-						Time: t_2015_06_21_01_23_45,
+						Time: t_2015_06_09_01_23_45_8327,
 					},
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
@@ -258,17 +270,17 @@
 					},
 				},
 				ArgTypes: []query_parser.OperandType{
-					query_parser.TypStr,
+					query_parser.TypTime,
 					query_parser.TypStr,
 				},
-				RetType:  query_parser.TypTime,
+				RetType:  query_parser.TypInt,
 				Computed: false,
 				RetValue: nil,
 			},
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypTime,
-					Time: t_2015_06_21_01_23_45,
+					Time: t_2015_06_09_01_23_45_8327,
 				},
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
@@ -276,18 +288,18 @@
 				},
 			},
 			&query_parser.Operand{
-				Type: query_parser.TypTime,
-				Time: t_2015_06_21_01,
+				Type: query_parser.TypInt,
+				Int:  1,
 			},
 		},
-		// YMDHM
+		// Minute
 		functionsTest{
 			&query_parser.Function{
-				Name: "YMDHM",
+				Name: "Minute",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypTime,
-						Time: t_2015_06_21_01_23_45,
+						Time: t_2015_06_09_01_23_45_8327,
 					},
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
@@ -295,17 +307,17 @@
 					},
 				},
 				ArgTypes: []query_parser.OperandType{
-					query_parser.TypStr,
+					query_parser.TypTime,
 					query_parser.TypStr,
 				},
-				RetType:  query_parser.TypTime,
+				RetType:  query_parser.TypInt,
 				Computed: false,
 				RetValue: nil,
 			},
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypTime,
-					Time: t_2015_06_21_01_23_45,
+					Time: t_2015_06_09_01_23_45_8327,
 				},
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
@@ -313,18 +325,18 @@
 				},
 			},
 			&query_parser.Operand{
-				Type: query_parser.TypTime,
-				Time: t_2015_06_21_01_23,
+				Type: query_parser.TypInt,
+				Int:  23,
 			},
 		},
-		// YMDHMS
+		// Second
 		functionsTest{
 			&query_parser.Function{
-				Name: "YMDHMS",
+				Name: "Second",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypTime,
-						Time: t_2015_06_21_01_23_45,
+						Time: t_2015_06_09_01_23_45_8327,
 					},
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
@@ -332,17 +344,17 @@
 					},
 				},
 				ArgTypes: []query_parser.OperandType{
-					query_parser.TypStr,
+					query_parser.TypTime,
 					query_parser.TypStr,
 				},
-				RetType:  query_parser.TypTime,
+				RetType:  query_parser.TypInt,
 				Computed: false,
 				RetValue: nil,
 			},
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypTime,
-					Time: t_2015_06_21_01_23_45,
+					Time: t_2015_06_09_01_23_45_8327,
 				},
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
@@ -350,8 +362,119 @@
 				},
 			},
 			&query_parser.Operand{
-				Type: query_parser.TypTime,
-				Time: t_2015_06_21_01_23_45,
+				Type: query_parser.TypInt,
+				Int:  45,
+			},
+		},
+		// Nanosecond
+		functionsTest{
+			&query_parser.Function{
+				Name: "Nanosecond",
+				Args: []*query_parser.Operand{
+					&query_parser.Operand{
+						Type: query_parser.TypTime,
+						Time: t_2015_06_09_01_23_45_8327,
+					},
+					&query_parser.Operand{
+						Type: query_parser.TypStr,
+						Str:  "America/Los_Angeles",
+					},
+				},
+				ArgTypes: []query_parser.OperandType{
+					query_parser.TypTime,
+					query_parser.TypStr,
+				},
+				RetType:  query_parser.TypInt,
+				Computed: false,
+				RetValue: nil,
+			},
+			[]*query_parser.Operand{
+				&query_parser.Operand{
+					Type: query_parser.TypTime,
+					Time: t_2015_06_09_01_23_45_8327,
+				},
+				&query_parser.Operand{
+					Type: query_parser.TypStr,
+					Str:  "America/Los_Angeles",
+				},
+			},
+			&query_parser.Operand{
+				Type: query_parser.TypInt,
+				Int:  8327,
+			},
+		},
+		// Weekday
+		functionsTest{
+			&query_parser.Function{
+				Name: "Weekday",
+				Args: []*query_parser.Operand{
+					&query_parser.Operand{
+						Type: query_parser.TypTime,
+						Time: t_2015_06_09_01_23_45_8327,
+					},
+					&query_parser.Operand{
+						Type: query_parser.TypStr,
+						Str:  "America/Los_Angeles",
+					},
+				},
+				ArgTypes: []query_parser.OperandType{
+					query_parser.TypTime,
+					query_parser.TypStr,
+				},
+				RetType:  query_parser.TypInt,
+				Computed: false,
+				RetValue: nil,
+			},
+			[]*query_parser.Operand{
+				&query_parser.Operand{
+					Type: query_parser.TypTime,
+					Time: t_2015_06_09_01_23_45_8327,
+				},
+				&query_parser.Operand{
+					Type: query_parser.TypStr,
+					Str:  "America/Los_Angeles",
+				},
+			},
+			&query_parser.Operand{
+				Type: query_parser.TypInt,
+				Int:  2,
+			},
+		},
+		// YearDay
+		functionsTest{
+			&query_parser.Function{
+				Name: "YearDay",
+				Args: []*query_parser.Operand{
+					&query_parser.Operand{
+						Type: query_parser.TypTime,
+						Time: t_2015_06_09_01_23_45_8327,
+					},
+					&query_parser.Operand{
+						Type: query_parser.TypStr,
+						Str:  "America/Los_Angeles",
+					},
+				},
+				ArgTypes: []query_parser.OperandType{
+					query_parser.TypTime,
+					query_parser.TypStr,
+				},
+				RetType:  query_parser.TypInt,
+				Computed: false,
+				RetValue: nil,
+			},
+			[]*query_parser.Operand{
+				&query_parser.Operand{
+					Type: query_parser.TypTime,
+					Time: t_2015_06_09_01_23_45_8327,
+				},
+				&query_parser.Operand{
+					Type: query_parser.TypStr,
+					Str:  "America/Los_Angeles",
+				},
+			},
+			&query_parser.Operand{
+				Type: query_parser.TypInt,
+				Int:  160,
 			},
 		},
 		// Lowercase
@@ -1242,13 +1365,17 @@
 
 func TestErrorFunctions(t *testing.T) {
 	tests := []functionsErrorTest{
-		// date
+		// time
 		functionsErrorTest{
 			&query_parser.Function{
-				Name: "date",
+				Name: "time",
 				Args: []*query_parser.Operand{
 					&query_parser.Operand{
 						Type: query_parser.TypStr,
+						Str:  "2006-01-02 MST",
+					},
+					&query_parser.Operand{
+						Type: query_parser.TypStr,
 						Str:  "2015-06-21 PDT",
 					},
 				},
@@ -1263,10 +1390,14 @@
 			[]*query_parser.Operand{
 				&query_parser.Operand{
 					Type: query_parser.TypStr,
+					Str:  "2006-01-02 MST",
+				},
+				&query_parser.Operand{
+					Type: query_parser.TypStr,
 					Str:  "2015-06-21 PDT",
 				},
 			},
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), int64(42), "Date"),
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), int64(42), "Time"),
 		},
 	}
 
diff --git a/v23/syncbase/nosql/internal/query/test/query_test.go b/v23/syncbase/nosql/internal/query/test/query_test.go
index b8d2abf..089c9ea 100644
--- a/v23/syncbase/nosql/internal/query/test/query_test.go
+++ b/v23/syncbase/nosql/internal/query/test/query_test.go
@@ -1064,7 +1064,7 @@
 		// Test functions.
 		{
 			// Select invoice records where date is 2015-03-17
-			"select v from Customer where Type(v) like \"%.Invoice\" and YMD(v.InvoiceDate, \"America/Los_Angeles\") = Date(\"2015-03-17 PDT\")",
+			"select v from Customer where Type(v) like \"%.Invoice\" and Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17",
 			[]string{"v"},
 			[][]*vdl.Value{
 				[]*vdl.Value{custTable.rows[5].value},
@@ -1073,7 +1073,7 @@
 		},
 		{
 			// Now will always be > 2012, so all customer records will be returned.
-			"select v from Customer where Now() > Date(\"2012-03-17 PDT\")",
+			"select v from Customer where Now() > Time(\"2006-01-02 MST\", \"2012-03-17 PDT\")",
 			[]string{"v"},
 			[][]*vdl.Value{
 				[]*vdl.Value{custTable.rows[0].value},
@@ -1093,7 +1093,7 @@
 			// Note: this wouldn't work for March as daylight saving occurs March 8
 			// and causes comparisons for those days to be off 1 hour.
 			// It would work to use UTC -- see next test.
-			"select k from Customer where YM(v.InvoiceDate, \"America/Los_Angeles\") = YM(Date(\"2015-04-01 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 4",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[7].key)},
@@ -1102,7 +1102,7 @@
 		},
 		{
 			// Select March 2015 UTC invoices.
-			"select k from Customer where YM(v.InvoiceDate, \"UTC\") = YM(Date(\"2015-03-01 UTC\"), \"UTC\")",
+			"select k from Customer where Year(v.InvoiceDate, \"UTC\") = 2015 and Month(v.InvoiceDate, \"UTC\") = 3",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[3].key)},
@@ -1112,7 +1112,7 @@
 		},
 		{
 			// Select 2015 UTC invoices.
-			"select k from Customer where Y(v.InvoiceDate, \"UTC\") = Y(Date(\"2015-01-01 UTC\"), \"UTC\")",
+			"select k from Customer where Year(v.InvoiceDate, \"UTC\") = 2015",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[1].key)},
@@ -1126,7 +1126,7 @@
 		},
 		{
 			// Select the Mar 17 2015 11:14:04 America/Los_Angeles invoice.
-			"select k from Customer where v.InvoiceDate = DateTime(\"2015-03-17 11:14:04 PDT\")",
+			"select k from Customer where v.InvoiceDate = Time(\"2006-01-02 15:04:05 MST\", \"2015-03-17 11:14:04 PDT\")",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[5].key)},
@@ -1134,7 +1134,7 @@
 		},
 		{
 			// Select invoices in the minute Mar 17 2015 11:14 America/Los_Angeles invoice.
-			"select k from Customer where YMDHM(v.InvoiceDate, \"America/Los_Angeles\") = YMDHM(DateTime(\"2015-03-17 11:14:00 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17 and Hour(v.InvoiceDate, \"America/Los_Angeles\") = 11 and Minute(v.InvoiceDate, \"America/Los_Angeles\") = 14",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[5].key)},
@@ -1142,7 +1142,7 @@
 		},
 		{
 			// Select invoices in the hour Mar 17 2015 11 hundred America/Los_Angeles invoice.
-			"select k from Customer where YMDH(v.InvoiceDate, \"America/Los_Angeles\") = YMDH(DateTime(\"2015-03-17 11:00:00 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17 and Hour(v.InvoiceDate, \"America/Los_Angeles\") = 11",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[5].key)},
@@ -1150,7 +1150,7 @@
 		},
 		{
 			// Select invoices on the day Mar 17 2015 America/Los_Angeles invoice.
-			"select k from Customer where YMD(v.InvoiceDate, \"America/Los_Angeles\") = YMD(Date(\"2015-03-17 PDT\"), \"America/Los_Angeles\")",
+			"select k from Customer where Year(v.InvoiceDate, \"America/Los_Angeles\") = 2015 and Month(v.InvoiceDate, \"America/Los_Angeles\") = 3 and Day(v.InvoiceDate, \"America/Los_Angeles\") = 17",
 			[]string{"k"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(custTable.rows[5].key)},
@@ -1181,10 +1181,10 @@
 			},
 		},
 		// Select clause functions.
-		// Date function
+		// Time function
 		{
-			"select Date(\"2015-07-01 PDT\") from Customer",
-			[]string{"Date"},
+			"select Time(\"2006-01-02 MST\", \"2015-07-01 PDT\") from Customer",
+			[]string{"Time"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01)},
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01)},
@@ -1198,10 +1198,10 @@
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01)},
 			},
 		},
-		// DateTime function
+		// Time function
 		{
-			"select DateTime(\"2015-07-01 01:23:45 PDT\") from Customer",
-			[]string{"DateTime"},
+			"select Time(\"2006-01-02 15:04:05 MST\", \"2015-07-01 01:23:45 PDT\") from Customer",
+			[]string{"Time"},
 			[][]*vdl.Value{
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01_01_23_45)},
 				[]*vdl.Value{vdl.ValueOf(t2015_07_01_01_23_45)},
@@ -1235,83 +1235,83 @@
 				[]*vdl.Value{vdl.ValueOf("JOHN STEED")},
 			},
 		},
-		// YMDHMS function
+		// Second function
 		{
-			"select k, YMDHMS(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Second(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMDHMS",
+				"Second",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12_22_16_06)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(6))},
 			},
 		},
-		// YMDHM function
+		// Minute function
 		{
-			"select k, YMDHM(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Minute(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMDHM",
+				"Minute",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12_22_16)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(16))},
 			},
 		},
-		// YMDH function
+		// Hour function
 		{
-			"select k, YMDH(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Hour(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMDH",
+				"Hour",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12_22)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(22))},
 			},
 		},
-		// YMD function
+		// Day function
 		{
-			"select k, YMD(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Day(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YMD",
+				"Day",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04_12)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(12))},
 			},
 		},
-		// YM function
+		// Month function
 		{
-			"select k, YM(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
+			"select k, Month(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"002003\"",
 			[]string{
 				"k",
-				"YM",
+				"Month",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(t2015_04)},
+				[]*vdl.Value{vdl.ValueOf("002003"), vdl.ValueOf(int64(4))},
 			},
 		},
-		// Y function
+		// Year function
 		{
-			"select k, Y(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
+			"select k, Year(v.InvoiceDate, \"America/Los_Angeles\") from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
 			[]string{
 				"k",
-				"Y",
+				"Year",
 			},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf("001001"), vdl.ValueOf(t2015)},
+				[]*vdl.Value{vdl.ValueOf("001001"), vdl.ValueOf(int64(2015))},
 			},
 		},
 		// Nested functions
 		{
-			"select Y(YM(YMD(YMDH(YMDHM(YMDHMS(v.InvoiceDate, \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\"), \"America/Los_Angeles\")  from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
-			[]string{"Y"},
+			"select Year(Time(\"2006-01-02 15:04:05 MST\", \"2015-07-01 01:23:45 PDT\"), \"America/Los_Angeles\")  from Customer where Type(v) like \"%.Invoice\" and k = \"001001\"",
+			[]string{"Year"},
 			[][]*vdl.Value{
-				[]*vdl.Value{vdl.ValueOf(t2015)},
+				[]*vdl.Value{vdl.ValueOf(int64(2015))},
 			},
 		},
 		// Bad arg to function.  Expression is false.
 		{
-			"select v from Customer where Type(v) like \"%.Invoice\" and YMD(v.InvoiceDate, v.Foo) = v.InvoiceDate",
+			"select v from Customer where Type(v) like \"%.Invoice\" and Day(v.InvoiceDate, v.Foo) = v.InvoiceDate",
 			[]string{"v"},
 			[][]*vdl.Value{},
 		},
@@ -1520,8 +1520,8 @@
 		},
 		// Test lots of types as map keys
 		{
-			"select v.B[true], v.By[10], v.U16[16], v.U32[32], v.U64[64], v.I16[17], v.I32[33], v.I64[65], v.F32[32.1], v.F64[64.2], v.C64[Complex(456.789, 10.1112)], v.C128[Complex(123.456, 11.2223)], v.S[\"Dickens\"], v.Ms[\"Charles\"][\"Dickens\"], v.T[DateTime(\"2015-07-01 01:23:45 PDT\")] from ManyMaps",
-			[]string{"v.B[true]", "v.By[10]", "v.U16[16]", "v.U32[32]", "v.U64[64]", "v.I16[17]", "v.I32[33]", "v.I64[65]", "v.F32[32.1]", "v.F64[64.2]", "v.C64[Complex]", "v.C128[Complex]", "v.S[Dickens]", "v.Ms[Charles][Dickens]", "v.T[DateTime]"},
+			"select v.B[true], v.By[10], v.U16[16], v.U32[32], v.U64[64], v.I16[17], v.I32[33], v.I64[65], v.F32[32.1], v.F64[64.2], v.C64[Complex(456.789, 10.1112)], v.C128[Complex(123.456, 11.2223)], v.S[\"Dickens\"], v.Ms[\"Charles\"][\"Dickens\"], v.T[Time(\"2006-01-02 15:04:05 MST\", \"2015-07-01 01:23:45 PDT\")] from ManyMaps",
+			[]string{"v.B[true]", "v.By[10]", "v.U16[16]", "v.U32[32]", "v.U64[64]", "v.I16[17]", "v.I32[33]", "v.I64[65]", "v.F32[32.1]", "v.F64[64.2]", "v.C64[Complex]", "v.C128[Complex]", "v.S[Dickens]", "v.Ms[Charles][Dickens]", "v.T[Time]"},
 			[][]*vdl.Value{
 				[]*vdl.Value{
 					vdl.ValueOf("It was the best of times,"),
@@ -1544,8 +1544,8 @@
 		},
 		// Test lots of types as set keys
 		{
-			"select v.B[true], v.By[10], v.U16[16], v.U32[32], v.U64[64], v.I16[17], v.I32[33], v.I64[65], v.F32[32.1], v.F64[64.2], v.C64[Complex(456.789, 10.1112)], v.C128[Complex(123.456, 11.2223)], v.S[\"Dickens\"], v.T[DateTime(\"2015-07-01 01:23:45 PDT\")] from ManySets",
-			[]string{"v.B[true]", "v.By[10]", "v.U16[16]", "v.U32[32]", "v.U64[64]", "v.I16[17]", "v.I32[33]", "v.I64[65]", "v.F32[32.1]", "v.F64[64.2]", "v.C64[Complex]", "v.C128[Complex]", "v.S[Dickens]", "v.T[DateTime]"},
+			"select v.B[true], v.By[10], v.U16[16], v.U32[32], v.U64[64], v.I16[17], v.I32[33], v.I64[65], v.F32[32.1], v.F64[64.2], v.C64[Complex(456.789, 10.1112)], v.C128[Complex(123.456, 11.2223)], v.S[\"Dickens\"], v.T[Time(\"2006-01-02 15:04:05 MST\", \"2015-07-01 01:23:45 PDT\")] from ManySets",
+			[]string{"v.B[true]", "v.By[10]", "v.U16[16]", "v.U32[32]", "v.U64[64]", "v.I16[17]", "v.I32[33]", "v.I64[65]", "v.F32[32.1]", "v.F64[64.2]", "v.C64[Complex]", "v.C128[Complex]", "v.S[Dickens]", "v.T[Time]"},
 			[][]*vdl.Value{
 				[]*vdl.Value{
 					vdl.ValueOf(true),
@@ -2821,36 +2821,36 @@
 			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Type"),
 		},
 		{
-			"select date(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Date"),
+			"select time(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Time"),
 		},
 		{
-			"select Datetime(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "DateTime"),
+			"select TimE(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Time"),
 		},
 		{
-			"select y(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Y"),
+			"select year(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Year"),
 		},
 		{
-			"select ym(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "YM"),
+			"select month(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Month"),
 		},
 		{
-			"select ymd(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "YMD"),
+			"select day(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Day"),
 		},
 		{
-			"select ymdh(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "YMDH"),
+			"select hour(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Hour"),
 		},
 		{
-			"select ymdhm(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "YMDHM"),
+			"select minute(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Minute"),
 		},
 		{
-			"select ymdhms(\"foo\") from Customer",
-			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "YMDHMS"),
+			"select second(\"foo\") from Customer",
+			syncql.NewErrDidYouMeanFunction(db.GetContext(), 7, "Second"),
 		},
 		{
 			"select now() from Customer",