Sphinx - sort by date and not by unix timestamp - sphinx

I need to view my results sorted by only the date part of the unix timestamp. I already have a datetime field in my database which I am converting to unixtimestamp for using with sphinx.
Sample Code In .conf file
SELECT id, deleted, posts, createdOn, publish, UNIX_TIMESTAMP(createdOn) as date1 , thread_title, first_post \
FROM posts
sql_attr_timestamp = date1
Thanking you
Imran

Sorting can be done using SetSortMode function:
$cl->SetSortMode ( SPH_SORT_ATTR_ASC, "date1" );
To sort by descending order use SPH_SORT_ATTR_DESC.

Related

How to add only date like 'DD/MM/YYYY' to timestamp in PostgreSQL?

I'm trying to add only the current date in "DD/MM/YYYY" format in a field of type ' timestamp in PostgreSQL' .
I try:
select to_char(now(),'DD/MM/YYYY') as date;
But PostgreSQL return me:
TIP : You will need to rewrite the expression or apply a type conversion.
There is no such thing as "only the date" in a timestamp field. A timestamp field will store timestamps.
Try using the date type instead. Please read about this here.
Also, please consider using the ISO 8601 format instead. Getting used to it helps in a lot of cases.
Human-readable formats like "DD/MM/YYYY" should only be used for presentation.
If you want to use timestamp fields and insert a human-readable formatted dates, then you are looking for:
to_timestamp('05/04/2016', 'DD/MM/YYYY')
If it is about the current date, then Postgres provides the CURRENT_DATE function, which you may use:
SELECT CURRENT_DATE;
INSERT INTO t (timestamp_field) VALUES (CURRENT_DATE);

SQL query to find date between a range of dates

Table X has start_date and end_date and related information associated with these dates. BOTH stored in DB in date format.
I need to find a specific date say 12th-Jan-2000 and extract the rows whose date range includes this date.
Could someone please help me out. I am new to SQL so need some guidance here.
Table X:
ID |start_date|end_date
1 |12/30/1999|01/12/2000
2 |01/20/2000|01/30/2000
3 |01/07/2000|01/15/2000
Thus my query should give back the ID-3 since 12th January falls in the range 01/07/2000-01/15/2000
Thanks
use the BETWEEN operator:
SELECT *
FROM TableX
WHERE DATE'2000-01-12' BETWEEN start_date AND end_date

Obtain date without timestamp in DB2

Please pardon my ignorance if I have missed any documentation/solution for the same. But I searched the web and could not find an answer.
I have a simple question. In the DB2 table,I have a column of type date and the with data of format 04/25/2013 12:00:00AM . When I query the DB2 database, I want to obtain just the date and not the timestamp i.e to obtain "04/25/2013" and not "04/25/2013 12:00:00AM". I tried DATE(column name) and just gave back the complete value including the time stamp.
This looks like a TIMESTAMP and not a DATE column. If it is indeed a TIMESTAMP column try this:
select varchar_format(current timestamp, 'MM/DD/YYYY') from sysibm.sysdummy1 ;
Just replace the current timestamp in the above example with your column and sysibm.sysdummy1 with your table.
The good thing about varchar_format is that it lets you easily format the timestamp. Just change the 'MM/DD/YYYY' part to 'YYYY.MM.DD' to get a format like '2017.08.18'.

How do extract just the date (without the time) from an integer field in SQLite3?

I have a small SQLite3 DB that has an integer field called "dt". It stores date and time.
I am having trouble extracting just the date from the field. However, doing a "select date(dt) from log2" returns nothing. I've tried strftime() as well, but no cigar.
Please help. This is driving me insane.
Thanks.
if the Date in dt is wellformed then the result shoeld be the date from a datetime column
select date('2011-01-01 23:55:55');
should receive
2011-01-01
but
select date('2011-01-01 23:55:5');
would receive nothing
so the dt coloum have to be wellformed

how to find earliest date and latest date from database

i want to perform email functionality in my app.In that in subject i have to add earliest date in database and latest date in database.so how can i get earliest date and latest date from database?I have database fields like
EntryDate which is datetime datatype
Amount
LastEdited with datetime datatype.
You need to run a query to sort date..like
SELECT TaskDate FROM MyTask Order By TaskDate limit 1
SELECT TaskDate FROM MyTask Order By TaskDate Desc limit 1
First one will give u oldest date and second will give the latest date.
hope this will help u out.