月份和年份…… [英] Month and Year......

查看:76
本文介绍了月份和年份……的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Frnds,
我在DB中有一个包含如下格式的字段
mm-yy/01
毫米是月(06)
yy是year(12)
我想知道如何从Datetime中提取唯一的mm-yy值,并将其与数字值组合在一起

例子是
06-12/01
06-12/02
06-12/03

01,02,03将递增.
怎么做.


请回复,
aamir

解决方案

假设您有一个autoincrement字段,那么只是选择所需信息的一种情况:

  SELECT   RIGHT ('   00' + 转换(> VARCHAR ,DATEPART(month,MyDate)), 2 )+ ' ( VARCHAR ,DATEPART(年份,MyDate)),' /' + ('  00' +  CONVERT ( VARCHAR ,Id), 2 ) As 代码来自 MyTable 


  SELECT  DATEPART(mm,dateField)+ ' -' + DATEPART(yy,dateField)+ ' /' + ROW_ NUMBER() OVER (> ORDER   BY 字段名称以设置订单订单类型)

 FROM  someTablename 



试试吧,它可能会解决您的问题.


亲爱的朋友们,
我得到了以下查询的解决方案
字符串月份= Convert.ToString(System.DateTime.Now.Month);
字符串年份= Convert.ToString(System.DateTime.Now.Year);
字符串y = year.Substring(2,2);
字符串格式=月+-" + y +"/";
但由于我的数据值格式如06-12/01 ... 06-12/02 ... 06-12/03,因此又出现了另一种需求...这应该如何生成值01,02,03 ..value应该在数据库中的每次保存单击上增加..并且当月份更改时,格式和数字也应进行修改,例如07-12/01 ... 07-12/02.

请回复
aamir


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

解决方案

Assuming that you have an autoincrement field, then it''s just a case of selecting the info you want:

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


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

FROM someTablename



Try with this, it might resolve your problem.


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


这篇关于月份和年份……的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆