HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

How could i search between two string type date

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
searchcoulddatetypetwobetweenhowstring

Problem

Consider these two tables. I use persian dates, so I have to declare startdate and enddate as a string(nvarchar(10)).

crt table:

id title startdate enddate
--------------------------
1  xyz   1395/01/01  1395/12/29
2  xyy   1394/12/01  1395/05/05
3  cvb   1392/02/03  1394/02/03


season table:

id title startdate enddate
--------------------------
1  spring95 1395/01/01  1395/03/31


I want to write a query that gives me crt records that are valid in a season. IE crt.startdate=season.enddate.

How do I do that?

Solution

If you encounter performance problems you could store the dates as integers instead of varchar. 1397-12-09 becomes 13971209, all the numbers remain in sequence so you can still carry out BETWEEN queries. Then convert your results to date format at the final point of presentation.

Context

StackExchange Database Administrators Q#156620, answer score: 3

Revisions (0)

No revisions yet.