Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Frnds,
i have a field in DB which contains format like below
mm-yy/01
mm is month(06)
yy is year(12)
i wnt to know how to extract the only the mm-yy values from Datetime and combine it with the number value

example is
06-12/01
06-12/02
06-12/03

01,02,03 will increment.
how can it be done.


Pl reply,
aamir
Posted
Comments
Vani Kulkarni 26-Jun-12 3:22am    
What have you tried till now?

Assuming that you have an autoincrement field, then it's just a case of selecting the info you want:
SQL
SELECT RIGHT('00'+ CONVERT(VARCHAR,DATEPART(month, MyDate)),2) + '-' + RIGHT(CONVERT(VARCHAR,DATEPART(YEAR, MyDate)),2) + '/' + RIGHT('00'+ CONVERT(VARCHAR,Id),2) As Code from MyTable
 
Share this answer
 
Comments
aamir07 26-Jun-12 4:37am    
Dear friends,
i got the solution for following query
string month = Convert.ToString(System.DateTime.Now.Month);
string year = Convert.ToString(System.DateTime.Now.Year);
string y = year.Substring(2, 2);
string format = month + "-" + y + "/";
but one more need arises as my data value is in format like 06-12/01...06-12/02...06-12/03...this how it should genrate the value the 01,02,03..value should get incremented on each save click in DB....and as the month changes the format and number should also get revised like 07-12/01...07-12/02.

pl reply
aamir
SQL
SELECT DATEPART(mm,dateField)+'-'+DATEPART(yy,dateField)+'/'+ROW_ NUMBER() OVER (ORDER BY Nameofthefieldtosetorder ordertype)

FROM someTablename


Try with this, it might resolve your problem.
 
Share this answer
 
Dear friends,
i got the solution for following query
string month = Convert.ToString(System.DateTime.Now.Month);
string year = Convert.ToString(System.DateTime.Now.Year);
string y = year.Substring(2, 2);
string format = month + "-" + y + "/";
but one more need arises as my data value is in format like 06-12/01...06-12/02...06-12/03...this how it should genrate the value the 01,02,03..value should get incremented on each save click in DB....and as the month changes the format and number should also get revised like 07-12/01...07-12/02.

pl reply
aamir
 
Share this answer
 
Comments
Sandeep Mewara 26-Jun-12 4:46am    
Post new question separately.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900