蜂巢日期转换不起作用

时间:2016-05-25 14:30:39

标签: date datetime hadoop hive unix-timestamp

我正在尝试比较不同格式的两个日期。因此,我将它们转换为unixtimespamp进行比较,但由于它们具有不同的日期格式。它没有正确的方式转换。我需要帮助。这是我的疑问:

select a.date,b.date
from table1 a join table2 b
on (from_unixtime( unix_timestamp(b.date, 'MM/dd/yyyy HH:mm:ss a')))=(from_unixtime(unix_timestamp(nvl(a.date,'3050-01-01 00:00:00.0'))));

日期格式为:

a.date                  b.date
4/12/2016 5:46:50 PM    2016-04-12 17:46:50.0
4/12/2016 5:46:50 PM    2016-04-12 17:46:50.0

非常感谢, stacky

2 个答案:

答案 0 :(得分:0)

看起来你已经倒退了日期治疗。 a.date是您需要为其指定格式的b.dateselect a.date,b.date from table1 a join table2 b on unix_timestamp(b.date) = unix_timestamp(a.date,'M/d/yyyy h:mm:ss a'); 应该很好地转换为没有任何准备的时间戳。以下在我的机器上测试良好:

//Detect installation.
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *currentBuild = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *versionOfLastVersionRun = [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionOfLastVersionRun"];
NSString *versionOfLastBuildRun = [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionOfLastBuildRun"];

//Copy all the bundle JSON
if (versionOfLastVersionRun == nil) {
    //Do something on first installation
} else if (![versionOfLastVersionRun isEqual:currentVersion]) {
    //Do something if there is a new version
} else if (![versionOfLastBuildRun isEqual:currentBuild]) {
    //Do something if there is a new build
}

//Save values.
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"VersionOfLastVersionRun"];
[[NSUserDefaults standardUserDefaults] setObject:currentBuild forKey:@"VersionOfLastBuildRun"];
[[NSUserDefaults standardUserDefaults] synchronize];

答案 1 :(得分:0)

我看到你正在将日期转换为long int。哪个更准确。那么为什么不比较它们才能看到它们是平等的。这是查询:

   select a.date,b.date from table1 a join table2 b on (unix_timestamp(b.date, 'MM/dd/yyyy HH:mm:ss a'))=(unix_timestamp(coalesce(a.date,'3050-01-01 00:00:00.0')));