Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date related issues..plz help me..

Author  Topic 

abhi143
Starting Member

32 Posts

Posted - 2006-01-23 : 02:43:37
Hi all of you,

iam having two problems related to date issues that i want to do in Stored procedure.

1) iam having one input text field, i want to do that user should enter the date in mm/dd format.
if user enter date in like thatt 1/5 then it append 0 before month and date i.e 01/05.

2)another issue is that in which i want to do that if user enter date 04/05/2004, then it will display on the same field as April 5, 2004.

plz help me regarding above two issues.


thanks

Abhi

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-23 : 02:49:51
1) can be done easily using charindex(), substring()

2) you can done using convert()

Check out Books OnLine for detail usage of the above funtions

-----------------
'KH'

I don't do homework
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-23 : 03:23:10
Where do you want to show the converted dates?
Use Front End Application to format the date in the format you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-23 : 23:27:00
hello all of u and khtan

thanks for the reply..

iam still facing problem in second issue, i have tried to used convert function to try to resolve it, but did not get it.

can plz u let me know, how to do that.


thanks

abhi
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-23 : 23:38:36
[code]declare
@strdt varchar(50)

select @strdt = '04/05/2004'
select convert(varchar(11), convert(datetime, @strdt), 100)[/code]

----------------------------------
'KH'

I do work from home but I don't do homework
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-24 : 00:04:13
Which Front End application are you using?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-24 : 04:40:25
thanx Khtan..

but iam having field type mm/dd..means user enter like 05/04 and display the result as May 4,

thanks

abhi
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-24 : 04:50:16
Which Front End application are you using?
Post the table structure

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-24 : 05:35:37
hello iam using xml, javascript for the validation of mm/dd format.

but in backend, i also want to update in sql server using stored procedure.

so i need help in Stored procedure for the mm/dd format.

if i enter 05/04, then display may, 4.

help me


thanks


abhi
Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-24 : 05:37:15
my date format is mm/dd abd display accordingly.

plz help

thanks

abhi

quote:
Originally posted by khtan

declare
@strdt varchar(50)

select @strdt = '04/05/2004'
select convert(varchar(11), convert(datetime, @strdt), 100)


----------------------------------
'KH'

I do work from home but I don't do homework


Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-25 : 03:40:00
plzzzz help meee
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-25 : 04:00:19
see these code
declare
@strdt varchar(50)

select @strdt = '04/05/2004'
select convert(varchar(11), convert(datetime, @strdt, 101), 100), convert(varchar(11), convert(datetime, @strdt, 103), 100)


----------------------------------
'KH'

Happy Chinese New Year
Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-25 : 06:01:03
thanx khtan..

but my prob doesnot get solved..

i want to display only April 5...

i doesnot want to display year.. i.e 2005

plz help

abhi

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-25 : 06:07:54
Use LEFT()
declare
@strdt varchar(50)

select @strdt = '04/05/2004'
select left(convert(varchar(11), convert(datetime, @strdt, 101), 100), 6), left(convert(varchar(11), convert(datetime, @strdt, 103), 100), 6)


----------------------------------
'KH'

Happy Chinese New Year
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-01-25 : 06:10:09
use this
append a default year if user is just inputting mm/dd

declare
@strdt varchar(50)

select @strdt = '04/15' +'/1900'
select convert(varchar(7), convert(datetime, @strdt,101), 100)
Go to Top of Page

abhi143
Starting Member

32 Posts

Posted - 2006-01-31 : 04:48:02
thanks all of u...
thanks shallu and khtan
iam getting month Apr, i need full month name i.e April..

plz help

abhi
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-31 : 05:28:24
It should be Front End work

declare @strdt varchar(50)

select @strdt = '04/15' +'/1900'
select Datename(month,convert(datetime, @strdt,101))+' '+cast(day(convert(datetime, @strdt,101)) as varchar) as Converted_date


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-31 : 06:37:57
Agreed. It should be done at the front end.

If you are doing it on the SQL Server side, the format will be fixed in the queries. If this is performed on the front end, it can be sensitive to the Control Panel's Date & Time settings

----------------------------------
'KH'


Go to Top of Page
   

- Advertisement -