Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Conversions to/from integers

Status
Not open for further replies.

CyberFan

Programmer
Jun 16, 2003
14
US

I'm trying to develop a Star Schema that is compatible with both DB2 and SQL Server. One of the biggest hurdles is dates.

The DB2 date() function will convert an integer into a date, similarly the days() function will convert a date into the number of days since 01/01/0001.

Does similar capability exist in SQL Server?


Thanks
 
If this is a conversion, then you can simply adjust the dates appropriately by comparing the integer value of today's date. If you want to maintain compatibility between the two, then that's more of a challenge because you would probably have to work with two different columns or dynamically adjust the dates.
In SQLServer to get the integer value (38370), just do this:
Code:
[Blue]SELECT[/Blue] [Fuchsia]Cast[/Fuchsia][Gray]([/Gray][Fuchsia]Cast[/Fuchsia][Gray]([/Gray][red]'1/20/05'[/red] [Blue]AS[/Blue] [Blue]datetime[/Blue][Gray])[/Gray] [Blue]AS[/Blue] [Blue]int[/Blue][Gray])[/Gray]

-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top