忙忙碌碌程序媛的工作小知识
C#计算第几周,修改红字部分就可以设定开始计算的第一天时间,将字符串格式转换成日期格式
这个链接是菜鸟教程在线编译器可以变异下面代码
http://www.runoob.com/try/runcode.php?filename=HelloWorld&type=cs
using System;
using System.Globalization;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
string start = "2016-01-03";
DateTime datemon = Convert.ToDateTime(start);
GregorianCalendar gc = new GregorianCalendar();
string weekOfYear = gc.GetWeekOfYear(datemon, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString();
Console.WriteLine(weekOfYear);
Console.ReadKey();
}
}
}
sql根据周来划分
有两种datepart(week, 日期时间的字段), datename(week,日期时间的字段),用的part感觉会把周期自动排了序
select datepart(week, a.CreateTm) as week,COUNT(*) as chancecount from table_T awhere and a.CreateTm>='2017-01-01' and a.CreateTm<'2018-01-01' group by datepart(week, a.CreateTm)
week也可以用别的替代
设置bootstrap十年控件,做之前一定不要忘记引入对应的文件,locales里面是各国语言包,默认是英文所以我用了中文包
$("#monthoption").attr('value', year.getFullYear()); c.year = year.getFullYear();//设置默认值为今年 $("#monthoption").datetimepicker({ language: 'zh-CN', format: 'yyyy', autoclose: true, startView: 4, minView: 4, todayBtn: true });
设置bootstrap年月控件
var date = new Date(); var nowmonth = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2);//有的时候一定需要两位数的月份 $("#monthoption").attr('value', nowmonth); $("#monthoption").datetimepicker({ language: 'zh-CN', format: 'yyyy-mm', autoclose: true, todayBtn: true, startView: 'year', minView: 'year', maxView: 'decade', todayBtn: true, });
convert转换时间年月日:附上w3school的介绍
http://www.w3school.com.cn/sql/func_convert.asp
stuff函数真的好用,,将一列数据用逗号隔开变成一串字符
stuff((select distinct ' ' + CnName from Product_T t where CiqCode = a.CiqCode for xml path('')), 1, 1, '')
获取一个月前的日期并且格式化
string startdate = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
string enddate = DateTime.Now.ToString("yyyy-MM-dd");
Sql根据事件段列举所有日期
这里的day可以换成其他week,month等等
select DATEADD(day,number,'2017-07-01')
from master.dbo.spt_values
where type='p' AND DATEADD(day,number,'2017-07-01') <='2017-08-01'