Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Added JDatabaseQuery function to extract part of timestamp. #758

Merged
merged 3 commits into from Jan 24, 2012

Conversation

gpongelli
Copy link
Contributor

This function is used to extract part of date from timestamp in a database independent manner.
Added MySQL test of element string conversion.

Usage:
$query->day($query->quoteName('dateColumn'))
for MySQL will return "DAY( dateColumn )"

$query->month($query->quoteName('dateColumn'))
for MySQL will return "MONTH( dateColumn )"

$query->year($query->quoteName('dateColumn'))
for MySQL will return "YEAR( dateColumn )"

$query->hour($query->quoteName('dateColumn'))
for MySQL will return "HOUR( dateColumn )"

$query->minute($query->quoteName('dateColumn'))
for MySQL will return "MINUTE( dateColumn )"

$query->second($query->quoteName('dateColumn'))
for MySQL will return "SECOND( dateColumn )"

database independent manner.
Added MySQL test of element string conversion.
@joomla-jenkins
Copy link

Unit testing complete. There were 1 failures and 0 errors from 1944 tests and 11088 assertions.
Checkstyle analysis reported 165 warnings and 0 errors.

@joomla-jenkins
Copy link

Build triggered by changes to the head.

Unit testing complete. There were 0 failures and 0 errors from 1944 tests and 11091 assertions.
Checkstyle analysis reported 165 warnings and 0 errors.

@chdemko
Copy link
Contributor

chdemko commented Jan 18, 2012

Would it be simpler to add these functions (and thus restrict the 'part' value)

public function year($date)
public function month($date)
public function day($date)
public function hour($date)
public function minute($date)
public function second($date)
public function microsecond($date)

?

Allowing to precise the 'part', developers could use some mysql functions that could not exist in other db engines

@gpongelli
Copy link
Contributor Author

Yes it could be simpler.
I've added only that function because of same word use in each database's documentation, but this proposal is interesting.

Ing. Gabriele Pongelli

"month", "day", "hour", "minute", "second" .
@eddieajau
Copy link
Contributor

Are there differences in the way different databases handle the date parts?

@gpongelli
Copy link
Contributor Author

Yes, an example extracting year from a date between MySQL and PostgreSQL .

Mysql: YEAR(dateColumn)
PostgreSQL: EXTRACT(YEAR FROM dateColumn)

Eng. Gabriele Pongelli

@eddieajau
Copy link
Contributor

Ok, in that case I agree with Christophe. I think it would be better to add the extra methods.

@gpongelli
Copy link
Contributor Author

I did the changes locally but I haven't pushed them yet, I'll do soon.

Eng. Gabriele Pongelli.

@gpongelli
Copy link
Contributor Author

Pushed last commits.

Eng. Gabriele Pongelli.

@joomla-jenkins
Copy link

Build triggered by changes to the head.

Unit testing complete. There were 0 failures and 0 errors from 1991 tests and 11149 assertions.
Checkstyle analysis reported 165 warnings and 0 errors.

eddieajau added a commit that referenced this pull request Jan 24, 2012
Added JDatabaseQuery function to extract part of timestamp.
@eddieajau eddieajau merged commit f26a989 into joomla:staging Jan 24, 2012
@eddieajau
Copy link
Contributor

Nice job. Merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants