Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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
 
Old March 15th, 2006, 08:48 AM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
 
Old March 15th, 2006, 10:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old March 15th, 2006, 08:59 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
 
Old March 15th, 2006, 09:13 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
 
Old March 15th, 2006, 09:15 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
 
Old March 16th, 2006, 04:12 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Matt, this is a SQL Language Forum.. your solution does not look mutch like SQL ;)

Gert

 
Old March 16th, 2006, 07:05 AM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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..
:)

 
Old March 16th, 2006, 09:26 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
 
Old March 17th, 2006, 03:56 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old March 19th, 2006, 09:51 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need advice to clean up my date manipulation code jasoncompo Beginning VB 6 1 June 2nd, 2006 01:29 PM
Date Manipulation pallone Javascript How-To 2 May 5th, 2006 02:15 PM
date code help needed. chooton JSP Basics 0 May 23rd, 2005 11:47 PM
Date Comparison Code Needed jackson_jl Beginning VB 6 0 March 14th, 2005 12:16 PM
Date manipulation otarboy Access 1 September 20th, 2004 11:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.