Jump to content

To get the date in desired format


Recommended Posts

Hi,

I have to send a date as input value to generate a report.

If it is monday i have to give the input dates as friday's date to today's date.

If it is other than monday i have to give the input values as previous date to today's date.

I used the _now() function which gives the data in the format YYYY/MM/DD

but I need the date in MM/DD/YY format. Also how to check for the monday conition.

Thanks in Advance.

Link to comment
Share on other sites

  • Moderators

venkat,

I believe this does what you want:

#Include <Date.au3>

Global $iYear, $iMon, $iDay

$iToday = _DateToDayValue(@YEAR, @MON, @MDAY)

If @WDAY = 2 Then
; Today is Monday
    $iStart = $iToday - 3
Else
; Today is not Monday
    $iStart = $iToday - 1
EndIf

_DayValueToDate($iStart, $iYear, $iMon, $iDay)
$sRange = $iDay & "/" & $iMon & "/" & StringRight($iYear, 2) & " - "
_DayValueToDate($iToday, $iYear, $iMon, $iDay)
$sRange &= $iDay & "/" & $iMon & "/" & StringRight($iYear, 2)

ConsoleWrite($sRange & @CRLF)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

I have to send a date as input value to generate a report.

If it is monday i have to give the input dates as friday's date to today's date.

If it is other than monday i have to give the input values as previous date to today's date.

I used the _now() function which gives the data in the format YYYY/MM/DD

but I need the date in MM/DD/YY format. Also how to check for the monday conition.

Thanks in Advance.

$pv_StrucA = DllStructCreate( "short Year;short Month;short Dow;short Day;short Hour;short Minute;short Second;short MSeconds" )

$av_dCallA = DllCall( $_DLL_PTR_Kernel32 , "int" , "GetLocalTime" , "ptr" , DllStructGetPtr( $pv_StrucA ) )
    ;void WINAPI GetLocalTime(
    ; __out LPSYSTEMTIME lpSystemTime
    ; );

$av_TimeW[0] = DllStructGetData( $pv_StrucA , "Month" )
$av_TimeW[1] = DllStructGetData( $pv_StrucA , "Day" )
$av_TimeW[2] = DllStructGetData( $pv_StrucA , "Year" )
$av_TimeW[3] = DllStructGetData( $pv_StrucA , "Hour" )
$av_TimeW[4] = DllStructGetData( $pv_StrucA , "Minute" )
$av_TimeW[5] = DllStructGetData( $pv_StrucA , "Second" )
$av_TimeW[6] = DllStructGetData( $pv_StrucA , "MSeconds" )
$av_TimeW[7] = DllStructGetData( $pv_StrucA , "Dow" )
Link to comment
Share on other sites

#include <Date.au3>
; todays date MM/DD/YY
ConsoleWrite(@MON & "/" & @MDAY & "/" & stringright(@YEAR, 2) & @LF)

; yesterdays date MM/DD/YY
ConsoleWrite(StringRegExpReplace(_DateAdd('D', -1, _NowCalcDate()), '\d{2}(\d{2})/(\d{2})/(\d{2})', '$2/$3/$1') & @LF)

; if today is monday then
If @WDAY = 2 Then
    $yesterday = StringRegExpReplace(_DateAdd('D', -1, _NowCalcDate()), '\d{2}(\d{2})/(\d{2})/(\d{2})', '$2/$3/$1')
    ; some code
EndIf

Link to comment
Share on other sites

Friend,

I made a mistake when describing the format.

Actually I need to give the input to an application.

I have attached the image which tells how and where input is to be given.

if monday

friday's date(mm/dd/yy) 09:30 today's date(mm.dd/yy) 09:30

else

previousdate(mm/dd/yy) 09:30 today's date(mm/dd/yy) 09:30

here the time remains constant.

After send("!vc")

filter window will open

send ("{tab 5}"}

where the cursor will be placed. I have to enter the value.

For Example (today)

04/06/09 09:30 send tab will take to another box where i have to enter 04/07/09 09:30

Thanks in Advance

venkat,

I believe this does what you want:

#Include <Date.au3>

Global $iYear, $iMon, $iDay

$iToday = _DateToDayValue(@YEAR, @MON, @MDAY)

If @WDAY = 2 Then
; Today is Monday
    $iStart = $iToday - 3
Else
; Today is not Monday
    $iStart = $iToday - 1
EndIf

_DayValueToDate($iStart, $iYear, $iMon, $iDay)
$sRange = $iDay & "/" & $iMon & "/" & StringRight($iYear, 2) & " - "
_DayValueToDate($iToday, $iYear, $iMon, $iDay)
$sRange &= $iDay & "/" & $iMon & "/" & StringRight($iYear, 2)

ConsoleWrite($sRange & @CRLF)

M23

post-48272-1239121482_thumb.jpg

Link to comment
Share on other sites

  • Moderators

venkat,

Try this:

#Include <Date.au3>

Global $iYear, $iMon, $iDay

$iToday = _DateToDayValue(@YEAR, @MON, @MDAY)

If @WDAY = 2 Then
; Today is Monday
    $iStart = $iToday - 3
Else
; Today is not Monday
    $iStart = $iToday - 1
EndIf

_DayValueToDate($iStart, $iYear, $iMon, $iDay)
$sDate1 = $iDay & "/" & $iMon & "/" & StringRight($iYear, 2) & " 09:30"
_DayValueToDate($iToday, $iYear, $iMon, $iDay)
$sDate2 = $iDay & "/" & $iMon & "/" & StringRight($iYear, 2) & " 09:30"

ConsoleWrite($sDate1 & @CRLF)
ConsoleWrite($sDate2 & @CRLF)

So just send these 2 strings and you should be set.

By the way, a slightly belated welcome to the AutoIt forums.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...