Jump to content
GuiSilva

[Resolvido] Obter numero da semana a partir de uma data

Recommended Posts

GuiSilva

Como posso obter o numero de uma semana no ano, a partir de uma data com o formato dia-mês-ano

Share this post


Link to post
Share on other sites
FDomingos

Partindo do principio que a tua data está no formato DateTime, tenta fazer o seguinte:

CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(new DateTime(ano, mes, dia), CalendarWeekRule.FirstDay, DayOfWeek.Sunday))

Importa o namespace System.Globalization.

Verifica se está no formato que necessitas.

Edited by FDomingos

Share this post


Link to post
Share on other sites
GuiSilva

Partindo do principio que a tua data está no formato DateTime, tenta fazer o seguinte:

CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(new DateTime(ano, mes, dia), CalendarWeekRule.FirstDay, DayOfWeek.Sunday))

Importa o namespace System.Globalization.

Verifica se está no formato que necessitas.

O que pretendo fazer é adicionar esse numero de semana a uma classe, desta forma <input class="TurmaComunicacao @estado @{CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(new DateTime(ano, mes, dia), CalendarWeekRule.FirstDay, DayOfWeek.Sunday))} "...

Mas "CultureInfo" e "CalendarWeekRule" dão o seguinte erro: the name 'CultureInfo' does not exist in the current context;

Share this post


Link to post
Share on other sites
FDomingos

Tens de importar o namespace System.Globalization. ex: using System.Globalization .

Share this post


Link to post
Share on other sites
GuiSilva

Tens de importar o namespace System.Globalization. ex: using System.Globalization .

já está importado e continua a dar o mesmo erro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.