|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
March 15th, 2006, 08:48 AM
|
Registered User
|
|
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
HELP Needed in Date Manipulation
I have a date 01-12-2000 in the database..
I want a function to change it to 01-12-2006..
ie, wanted to split dd-mm-yyyy into dd-mm and yyyy
and concatinate it with yyyy' to get dd-mm-yyyy'
Please help me if you know how to do this...
|
March 15th, 2006, 10:34 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What do you wish to do, change all references to 01-12-2000 to 01-12-2006 or to add six years to all the dates? A different reply would hold for each case.
Rand
|
March 15th, 2006, 08:59 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
This function should do it:
<%
FUNCTION tweakDate(varDate,yearVal)
IF isNull(varDate) OR Trim(varDate) = "" OR varDate = "Null" THEN
tweakDate = "Null"
ELSE
tweakDate = "" & day(DateValue(varDate)) & "/" & month(DateValue(varDate)) & "/" & yearVal
END IF
END FUNCTION
response.write tweakdate(date(),"2006")
%>
Wind is your friend
Matt
|
March 15th, 2006, 09:13 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
mmmm, re-reading your post I think you need to replace:
response.write tweakdate(date(),"2006")
with
response.write tweakdate([your database date value],"2006")
Wind is your friend
Matt
|
March 15th, 2006, 09:15 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
agggggh Im not with it today. I have used a / as a seperator you wish for a -
I assume you can make this simple change?
Wind is your friend
Matt
|
March 16th, 2006, 04:12 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Matt, this is a SQL Language Forum.. your solution does not look mutch like SQL ;)
Gert
|
March 16th, 2006, 07:05 AM
|
Registered User
|
|
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I got it, if anybody like to know see the function below..
date(rtrim(char(month(input_date)))||'/'||rtrim(char(day(input_date)))||'/'||char(new_year))
if input_date = 31/01/2000
and new_year = 2006
then output will be 2006/01/31(with data type DATE)
Thanks to all who responded..
:)
|
March 16th, 2006, 09:26 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Gert - where do you think you use this funtion? Inside an sql statement - what are you on about?
EG:
sql = "SELECT dateValue,...,..;"
set getdateValue = conn.execute(sql)
sql = "UPDATE tbleName SET dateValue = '" & tweakdate(getdateValue(0),"2006")
& '" where ID=[someID]
Do you dis agree? or do you reckon I should stick to the ASP area, youve got a cheek...
Kunjan:
You asked for:
;;and concatinate it with yyyy' to get dd-mm-yyyy'
Now you say:
;;;then output will be 2006/01/31(with data type DATE)
You never asked for yyyy/dd/mm
Over n out
Wind is your friend
Matt
|
March 17th, 2006, 03:56 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Matt - no need to be upset (tried to keep it in a light tone with the smiley..), and I'm afraid I don't understand what the phrase "youve got a cheek" is supposed to mean..
I just thought that since Kunjan didn't mention anything about a programming language, and since he made the post in a SQL forum, then he might needed something to work in SQL, not ASP. But since I am most familiar with SQL Server, your solution might be for some other SQL-language for all I know. In that case, I apologize.
Gert
|
March 19th, 2006, 09:51 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Not up set and yes I did see the smiley.
You are correct maybe he is not using ASP. If so my VBScript function may be of no use. No need to apologize - re reading the post, yes, i may have been a bit abrupt - sorry bout that.
Have a nice day.
Wind is your friend
Matt
|
|
|